Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#无法从字符串转换为System.IO.Stream_C#_Windows_File_Io_Stream - Fatal编程技术网

C#无法从字符串转换为System.IO.Stream

C#无法从字符串转换为System.IO.Stream,c#,windows,file,io,stream,C#,Windows,File,Io,Stream,我写了这篇文章,得到了错误“参数1:无法从'string'转换为'System.IO.Stream'。 我在一个控制台应用程序中使用了完全相同的代码,它工作得很好,但将其放入Windows通用应用程序会出现此错误。您尝试过吗 System.IO.StreamReader file = new System.IO.StreamReader("saveData.txt"); 看起来Windows通用应用程序读取文件的功能有所不同: MemoryStream memoryStream= new Me

我写了这篇文章,得到了错误“参数1:无法从'string'转换为'System.IO.Stream'。 我在一个控制台应用程序中使用了完全相同的代码,它工作得很好,但将其放入Windows通用应用程序会出现此错误。

您尝试过吗

System.IO.StreamReader file = new System.IO.StreamReader("saveData.txt");

看起来Windows通用应用程序读取文件的功能有所不同:

MemoryStream memoryStream= new MemoryStream(Encoding.UTF8.GetBytes("saveData.txt"));
资料来源:

var file = await ApplicationData.Current.LocalFolder.GetFileAsync("data.txt");
var lines = await FileIO.ReadLinesAsync(file);