【问题标题】:How to read the text from another computer如何从另一台计算机读取文本
【发布时间】:2017-05-17 10:09:12
【问题描述】:

我尝试使用 IP 地址从其他计算机读取文件,但我无法读取该文件。它引发了异常,例如“找不到路径的一部分 'E:\IPFile_Read\IPFile_Read\ bin\Debug\@\IPAddress\Test\News.txt'"

代码:

 {

                StreamReader sr = new StreamReader("@\\IPaddress\\Test\\News.txt");
                line = sr.ReadLine();

                while (line != null)
                {
                    text_Data.Text = line;
                    line = sr.ReadLine();
                }
                sr.Close();
                Console.ReadLine();
            }

如何从另一台计算机读取文本文件。

【问题讨论】:

    标签: c# .net file ip-address readfile


    【解决方案1】:

    "@\\IPaddress\\Test\\News.txt" 应该是 @"\\IPaddress\Test\News.txt"。对于逐字字符串,@ 放在开头引号之前,如果您使用的是逐字字符串,则不需要转义斜杠。 UNC 前缀仍然需要\\,因为它确实有两个反斜杠。

    【讨论】:

      猜你喜欢
      • 2013-09-26
      • 1970-01-01
      • 2011-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-18
      相关资源
      最近更新 更多