繁体   English   中英

读取文本文件C#

[英]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());
            }
        }
    }

这在我创建Windows应用程序时非常有效。

当我在设备应用程序中使用相同的代码时 - Windows CE我收到错误:

在此输入图像描述

使用:.Net 2.0,visual Studio 2005

您的设备没有c驱动器。 更换

string fileLoc = @"c:\wms.txt";

string fileLoc = @"wms.txt";

看来根文件夹会自动用\\添加到您的路径中

Windows CE没有驱动器号的概念。 你的路径应该只是@"\\wms.txt"

尝试

string fileLoc = @"c:\wms.txt";

要么

string fileLoc = "c:\\wms.txt";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM