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

Ven*_*gat -1 .net c# file ip-address readfile

我试图使用IP地址从其他计算机读取该文件,但我无法读取该文件.它引发了异常,如"无法找到路径的一部分"E:\ IPFile_Read\IPFile_Read\bin\Debug\@\ip地址\测试\ 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();
            }
Run Code Online (Sandbox Code Playgroud)

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

Rog*_*mbe 6

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