在windows mobile 6.5中如何在文件中读/写文本
答案 0 :(得分: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;
}
}
答案 1 :(得分: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;
}
}
}