VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • vb.net教程之C#和VB.net语法对比图(2)

 

using System.IO;


//Write out to text file
StreamWriter writer = File.CreateText
  ("c:myfile.txt");
writer.WriteLine("Out to file.");
writer.Close();


//Read all lines from text file
StreamReader reader = File.OpenText
  ("c:myfile.txt");
string line = reader.ReadLine();
while (line != null) {
  Console.WriteLine(line);
  line = reader.ReadLine();
}
reader.Close();


//Write out to binary file
string str = "Text data";
int num = 123;
BinaryWriter binWriter = new BinaryWriter(File.OpenWrite
  ("c:myfile.dat"));
binWriter.Write(str);
binWriter.Write(num);
binWriter.Close();


//Read from binary file
BinaryReader binReader = new BinaryReader(File.OpenRead
  ("c:myfile.dat"));
str = binReader.ReadString();
num = binReader.ReadInt32();
binReader.Close();


相关教程