请问如何能读取一个TXT文件?
请问各路前辈如何能读取一个TXT文件?
------解决方案-------------------- virtual public string[] strNoValidChar()
{
string sLine = "";
ArrayList list = new ArrayList();
if (!File.Exists("NoValidChar.txt"))
return (string[])list.ToArray(typeof(string));
StreamReader sr = File.OpenText(Path.GetFileName("NoValidChar.txt"));
while (sLine != null)
{
sLine = sr.ReadLine();
if (sLine != null)
list.Add(sLine);
}
sr.Close();
return (string[])list.ToArray(typeof(string));
}
------解决方案--------------------openFileDialog1.InitialDirectory = ("E:\\C#");
openFileDialog1.Filter = "Text(*.txt)|*.txt|Word(*.doc)|*doc|all File(*.*)|*.*|TXL(*.Txl)|*.Txl";
DialogResult r = openFileDialog1.ShowDialog();
string filepath = openFileDialog1.FileName;
if (r == DialogResult.OK)
{
System.IO.FileStream fs;
fs = new FileStream(openFileDialog1.FileName,System.IO.FileMode.Open);
BinaryReader sr = new BinaryReader(fs);
string ss = (sr.ReadChar()).ToString();
while(ss!="\r")
{
textBox1.Text+=ss;
ss = (sr.ReadChar()).ToString();
}
}
文本文件打开方式