[英]Read text file C#
private void button1_Click(object sender, EventArgs e)
{
string fileLoc = @"c:\wms.txt";
if (File.Exists(fileLoc))
{
using (TextReader tr = new StreamReader(fileLoc))
{
MessageBox.Show(tr.ReadLine());
}
}
}
This works perfectly in when I create a Windows Application. 这在我创建Windows应用程序时非常有效。
When I use the same code in a Device application - Windows CE i get error: 当我在设备应用程序中使用相同的代码时 - Windows CE我收到错误:
Using: .Net 2.0 , visual Studio 2005 使用:.Net 2.0,visual Studio 2005
Your device does not have a c
drive. 您的设备没有
c
驱动器。 Replace 更换
string fileLoc = @"c:\wms.txt";
with 同
string fileLoc = @"wms.txt";
It seems that the root folder is automatically added to your path with a \\
看来根文件夹会自动用
\\
添加到您的路径中
Windows CE does not have a concept of drive letters . Windows CE没有驱动器号的概念。 Your path there should simply be
@"\\wms.txt"
. 你的路径应该只是
@"\\wms.txt"
。
try 尝试
string fileLoc = @"c:\wms.txt";
or 要么
string fileLoc = "c:\\wms.txt";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.