Code for Reading and writing from a file in c#?



Code for Reading and writing from a file in c#?..

Answer / sabina

StreamWriter and StreamReader can be used to read and write
unicode chars to a file.

TextWriter adn TextReader are abstract base class from
which SW and SR inherits.

Stream is an abstract base class supports reading and
writing bytes into a file(arrays -> file) (file -> arrays)

FileStream exposes the stream ard the file

BinaryStream is used to write and read primitive
datatypes/encoded strings to files.

to encode string to bytes

byte[] b = new UTF8Encoding(true).GetBytes(string);

to decode string from bytes

String str = new UTF8Encodeing(true).GetString(b);

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Sharp Code Interview Questions

How to export 2 datatables of a single dataset to 2 different worksheets of a single MSExcel file ?

0 Answers   Eastcom Systems,


how to change password in .net with c # with ado.net and also SQL server 2008 change password

1 Answers  


Using C# Write a program that performs the following. The user inputs a number and then enters a series of numbers from 1 to that number. Your program should determine which number (or numbers) is missing or duplicated in the series, if any. For example, if the user entered 5 as the initial number and then entered the following sequences, the results should be as shown. Input Sequence Output ---------------------- --------------- 1 2 3 4 5 Nothing bad However, if 7 were the high number, the user would see the results on the right for the following number entries: Input Sequence Output ---------------------- --------------- 1 3 2 4 5 Missing 6 Missing 7 And if 10 were the high number and the user entered the numbers shown on the left, note the list of missing and duplicate numbers: Input Sequence Output ---------------------- --------------- 1 2 4 7 4 4 5 10 8 2 6 Duplicate 2 ( 2 times) Missing 3 Duplicate 4 ( 3 times ) Missing 9 The program should check the high number that the user inputs to ensure that it does not exceed the size of any array you might be using for storage.

0 Answers  


How to Create Files by Using the FileInfo Class?

1 Answers  


Write a program to input an integer and - display the reverse - display the sum of each digit - should include logic that considers the input number as any number of digits long

2 Answers   Mind Tree,






c# code to Count number of 1's in a given range of integer (0 to n)

0 Answers  


Write a function which accepts a sentence as input parameter.Each word in that sentence is to be reversed. Space should be there between each words.Return the sentence with reversed words to main function and produce the required output. for eg:- i/p: jack jill jung kill o/p: kcaj llij gnuj llik

1 Answers   Mind Tree,


Code for Searching for Multiple Matches with the MatchCollection Class?

0 Answers   TCS,


Coding for Manipulate XML File Data Using C#?

1 Answers  


Hello I am hosting remoting within IIS. Everything works just fine as long as I allow anonymous access at the IIS level. When I allow only Windows Authenticated sessions, something very strange happens: If the client activates the remote object with IP address - works fine If the client activates it using a machine name - get http 401 exception is thrown. The exception is thrown when the client calls the remote method. I set the channel's useDefaultCredentials property to true. Any idea how to allow Windows Authentication? Here is the call stack: System.Net.WebException: The remote server returned an error: (401) Unauthorized .. ---> System.ComponentModel.Win32Exception: The target principal name is incorrect at System.Net.NTAuthentication.GetOutgoingBlob(Byte[] incomingBlob, Boolean handshakeComplete) at System.Net.NTAuthentication.GetOutgoingBlob(String incomingBlob, Boolean handshakeComplete) at System.Net.NegotiateClient.DoAuthenticate(String challenge, WebRequest webRequest, ICredentials credentials, Boolean preAuthenticate) at System.Net.NegotiateClient.DoAuthenticate(String challenge, WebRequest webRequest, ICredentials credentials, Boolean preAuthenticate) at System.Net.NegotiateClient.Authenticate(String challenge, WebRequest webRequest, ICredentials credentials) at System.Net.AuthenticationManager.Authenticate(String challenge, WebRequest request, ICredentials credentials) at System.Net.AuthenticationState.AttemptAuthenticate (HttpWebRequest httpWebRequest, ICredentials authInfo) --- End of inner exception stack trace ---

0 Answers   Infosys,


Code for Working with Files under a Directory?

1 Answers  


program to reverse the order of digits in a given number of any length.

1 Answers   Mind Tree,


Categories
  • ASP.NET Code Interview Questions ASP.NET Code (46)
  • VB.NET Code Interview Questions VB.NET Code (9)
  • C Sharp Code Interview Questions C Sharp Code (51)
  • ADO.NET Code Interview Questions ADO.NET Code (8)