在 windows mobile 6.5 中如何读/写文件中的文本
问问题
4611 次
2 回答
3
windows mobile 6.5 如何在文件中写入/读取文本在 设计视图中插入标签(label1)在代码中添加以下行
代码:
string path = "\\test.txt";//file Loc: *start->file explorer->text.txt*
if (!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("Hello");
sw.WriteLine("And");
sw.WriteLine("Welcome");
}
}
using (StreamReader sr = File.OpenText(path))
{
string s = "";
label1.Text = "";
while ((s = sr.ReadLine()) != null)
{
label1.Text += s;
}
}
于 2010-12-29T11:57:14.497 回答
0
写入文件
FileInfo fi = new FileInfo(Path+"\\txtServer.inf");//\\Application
using (TextWriter txtWriter = new StreamWriter(fi.Open(FileMode.Truncate)))
{
txtWriter.WriteLine("Hello");
}
从文件中读取
string path = Path + "\\txtServer.inf";//\\Application
if (!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path))
{
}
}
else
{
using (StreamReader sr = File.OpenText(path))
{
string s = "";
Label1.Text ="";
while ((s = sr.ReadLine()) != null)
{
Label1.Text = s;
}
}
}
于 2015-01-15T03:52:39.447 回答