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

How to read the text from another computer

我尝试使用 IP 地址从其他计算机读取文件,但我无法读取 one.It 引发的异常 "Could not find a part of the path '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();
            }

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

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