1. Add a named emptybetween
Copy the codeThe code is as follows:
;
;
2. Reading of files
(1). Use the FileStream class to read the file, convert it into a char array, and then output it.
Copy the codeThe code is as follows:
byte[] byData = new byte[100];
char[] charData = new char[1000];
public void Read()
{
try
{
FileStream file = new FileStream("E:\\", );
(0, );
(byData, 0, 100); //ByData is the byte array passed in by byData to accept data in the FileStream object. The second parameter is the location where the data is started to be written in the byte array. It is usually 0, indicating that data is written to the array from the beginning file of the array. The last parameter specifies how many characters to read from the file.
Decoder d = ();
(byData, 0, , charData, 0);
(charData);
();
}
catch (IOException e)
{
(());
}
}
(2). Use StreamReader to read the file and then output it line by line.
Copy the codeThe code is as follows:
public void Read(string path)
{
StreamReader sr = new StreamReader(path,);
String line;
while ((line = ()) != null)
{
(());
}
}
3. File writing
(1). Create a file using the FileStream class and then write the data to the file.
Copy the codeThe code is as follows:
public void Write()
{
FileStream fs = new FileStream("E:\\", );
//Get the byte array
byte[] data = ("Hello World!");
//Start writing
(data, 0, );
//Clear the buffer and close the stream
();
();
}
(2). Create a file using the FileStream class, and write data to the file using the StreamWriter class.
Copy the codeThe code is as follows:
public void Write(string path)
{
FileStream fs = new FileStream(path, );
StreamWriter sw = new StreamWriter(fs);
//Start writing
("Hello World!!!!");
//Clear the buffer
();
//Close the stream
();
();
}