关于代码页使用的情况
using
System;
using System.IO;
using System.Text;
public class TextFromFile
... {
private const string FILE_NAME = "SQL.txt";
public static void Main()
...{
if (!File.Exists(FILE_NAME))
...{
Console.WriteLine("{0} does not exist.", FILE_NAME);
return;
}
//Encoding encod = Encoding.GetEncoding(936);
using (StreamReader sr = new StreamReader(FILE_NAME, Encoding.GetEncoding(936)))
...{
StringBuilder sb = new StringBuilder();
String input;
while ((input=sr.ReadLine())!=null)
...{
string line = input.Trim();
int pos = line.IndexOf("--");
if(pos >= 0)
line = line.Remove(pos);
if(!String.IsNullOrEmpty(line))
...{
sb.Append(line);
if(line.IndexOf(';') >= 0)
...{
Console.WriteLine(sb.ToString());
sb.Length = 0;
}
}
}
Console.WriteLine ("The end of the stream has been reached.");
sr.Close();
}
}
}
using System.IO;
using System.Text;
public class TextFromFile
... {
private const string FILE_NAME = "SQL.txt";
public static void Main()
...{
if (!File.Exists(FILE_NAME))
...{
Console.WriteLine("{0} does not exist.", FILE_NAME);
return;
}
//Encoding encod = Encoding.GetEncoding(936);
using (StreamReader sr = new StreamReader(FILE_NAME, Encoding.GetEncoding(936)))
...{
StringBuilder sb = new StringBuilder();
String input;
while ((input=sr.ReadLine())!=null)
...{
string line = input.Trim();
int pos = line.IndexOf("--");
if(pos >= 0)
line = line.Remove(pos);
if(!String.IsNullOrEmpty(line))
...{
sb.Append(line);
if(line.IndexOf(';') >= 0)
...{
Console.WriteLine(sb.ToString());
sb.Length = 0;
}
}
}
Console.WriteLine ("The end of the stream has been reached.");
sr.Close();
}
}
}