Read numbers from a text file in C#

前端 未结 7 1334
别那么骄傲
别那么骄傲 2020-12-14 18:21

This is something that should be very simple. I just want to read numbers and words from a text file that consists of tokens separated by white space. How do you do this in

7条回答
  •  悲哀的现实
    2020-12-14 18:25

    I like using the StreamReader for quick and easy file access. Something like....

      String file = "data_file.txt";    
      StreamReader dataStream = new StreamReader(file);   
      string datasample;
      while ((datasample = dataStream.ReadLine()) != null)
      {
    
         // datasample has the current line of text - write it to the console.
         Console.Writeline(datasample);
      }
    

提交回复
热议问题