ReadAllLines for a Stream object?

后端 未结 6 797
醉酒成梦
醉酒成梦 2020-12-01 11:31

There exists a File.ReadAllLines but not a Stream.ReadAllLines.

using (Stream stream = Assembly.GetExecutingAssembly().GetManifestR         


        
6条回答
  •  -上瘾入骨i
    2020-12-01 12:29

    If you want to use StreamReader then yes, you will have to use ReadLine and loop throught the StreamReader, reading line by line.

    Something like that:

    string line;
    
    using (StreamReader reader = new StreamReader(stream))
    {
        while ((line = reader.ReadLine()) != null)
        {   
            Console.WriteLine(line); 
        }
    }
    

    or try

    using (StreamReader reader = new StreamReader("file.txt"))
        {
    
           string[] content = reader.ReadToEnd().Replace("\n","").Split('\t');
        }
    

提交回复
热议问题