本人新手,最近碰到一个问题,使用扫描枪离线功能,使用窗口读取本地txt文档的内容在listview里显示, 并且可以修改,改完后在txt文档里保存,求高手指点。
解决方案
40
读:
public void GetTxtRead(string path, ref List<string> listStr)
{
StreamReader sr = new StreamReader(path, Encoding.Default);
String line;
while ((line = sr.ReadLine()) != null)
{
listStr.Add(line.ToString());
}
sr.Close();
}
写:
public void RecordTxt(string path, string date, string winCode,string minute)
{
FileInfo finfo = new FileInfo(path);
if (!finfo.Exists)
{
FileStream stream;
stream = File.Create(path);
stream.Close();
}
FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
fs.Seek(0, SeekOrigin.Begin);
fs.SetLength(0);
fs.Close();
StreamWriter w = new StreamWriter(path);
w.BaseStream.Seek(0, SeekOrigin.End);
public void GetTxtRead(string path, ref List<string> listStr)
{
StreamReader sr = new StreamReader(path, Encoding.Default);
String line;
while ((line = sr.ReadLine()) != null)
{
listStr.Add(line.ToString());
}
sr.Close();
}
写:
public void RecordTxt(string path, string date, string winCode,string minute)
{
FileInfo finfo = new FileInfo(path);
if (!finfo.Exists)
{
FileStream stream;
stream = File.Create(path);
stream.Close();
}
FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
fs.Seek(0, SeekOrigin.Begin);
fs.SetLength(0);
fs.Close();
StreamWriter w = new StreamWriter(path);
w.BaseStream.Seek(0, SeekOrigin.End);
w.Write(date + “\r\n” + winCode+”\r\n” + minute);
w.Close();
}