简体   繁体   English

StreamReader不带字符串吗?

[英]StreamReader doesn't take string?

I'm trying to read a file with a StreamReader, but I get an error for using path 我正在尝试使用StreamReader读取文件,但是使用path出现错误

Argument 1: cannot convert from 'string' to System.IO.Stream 参数1:无法从“字符串”转换为System.IO.Stream

even though it's clear from the documentation , that you should be able to use a string. 即使从文档中可以明显看出,您也应该可以使用字符串。
What am I missing here? 我在这里想念什么?

public MyClass Load(String path)
{
    try
    {
        // exception in this line, `path` is underlined with red
        using (StreamReader reader = new StreamReader(path)) 
        {
            String line = reader.ReadLine();
// ... etc

我无法告诉您答案是否正确,但UWP的正确语法如下:

using (var sr = new StreamReader(new FileStream(filenamestring, FileMode.Open)))

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

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