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

Write a program which has a function and that function should take 2 or 3 or any number of strings and it should return the largest common prefix of all those strings. If there is no common prefix it should return an empty string. for eg:- INPUT OUTPUT glo {glory,glorious,glod} gl {glad,glow} {calendar,phone} empty string

2 Answers   Mind Tree,


How to Create a Treeview Menu in ASP.NET with C#?

1 Answers  


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

0 Answers   Eastcom Systems,


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,


program for straight line(y=mx+c)

0 Answers   Mind Tree,






program to check if a number is "perfect number".

1 Answers   Mind Tree, SoftSol,


Write a program to convert postfix expression to infix expression.

0 Answers   Mind Tree,


How to Create Files by Using the FileInfo Class?

1 Answers  


Write a program to count 3Letter, 4Letter and 5Letter words from a file and print the number of 3Letter, 4Letter and 5Letter words. Delimiter is space, tab, hifen. Also we should not consider the line in the file after we encounter # in that line.

0 Answers   Mind Tree,


c# coding for a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors not using the Big-integer and Exponential Function's.

1 Answers   TCS,


How to find No of classes,Packages,No of Methods per Classes and Depth of Inheritance for selecting source code in windows form application using c# .net? (Source code is input Program. It may be Java or .net) Please help me..) Thanks..)

0 Answers  


Create a class called Accounts which has data members like ACCOUNT no, Customer name, Account type, Transaction type (d/w), amount, balance D->Deposit W->Withdrawal If transaction type is deposit call the credit(int amount) and update balance in this method. If transaction type is withdraw call debit(int amt) and update balance. Pass the other information like Account no,name,Account Type through constructor. Call the show data method to display the values.

1 Answers   Cognizant,


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)