Home > Net >  C # winform how to read TXT file content
C # winform how to read TXT file content

Time:10-21

How to write and read the contents of the TXT file

CodePudding user response:

File. Read readalltext, File. Writealltext writes

CodePudding user response:

And winform it doesn't matter, with the System. IO under this namespace class can do it

CodePudding user response:

Using reader As StreamReader=File. OpenText (" d: \ a.t xt ")
Dim As String=s reader. ReadToEnd ()
The End Using

CodePudding user response:

Read the file:
Public void Read (string path)
{
}

CodePudding user response:

//read 
Public void Read (string path)
{
StreamReader sr=new StreamReader ();
The string line;
The line=sr. ReadLine ();
While (the line!=null)
{
Console. WriteLine (line. The ToString ());
}
}

//write
Public void a Write (string path, string context)
{
FileStream fs=new FileStream (path, FileMode. Create);
Byte [] data=https://bbs.csdn.net/topics/System.Text.Encoding.Default.GetBytes (context);
Fs. Write (data, 0, the data length);
Fs. Flush ();
fs.Close();
}
  •  Tags:  
  • C #
  • Related