Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading and displaying data from a .txt file

Tags:

How do you read and display data from .txt files?

like image 975
Jessy Avatar asked Apr 08 '09 18:04

Jessy


People also ask

How do I read data from a text file?

To read from a text fileUse the ReadAllText method of the My. Computer. FileSystem object to read the contents of a text file into a string, supplying the path. The following example reads the contents of test.

Which object is used for reading from a text file?

A simple text scanner that can parse primitive types and strings using regular expressions. A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace.

How do I read a .TXT file in Matlab?

Use fopen to open the file, specify the character encoding, and obtain the fileID value. When you finish reading, close the file by calling fclose(fileID) . A = fscanf( fileID , formatSpec , sizeA ) reads file data into an array, A , with dimensions, sizeA , and positions the file pointer after the last value read.


1 Answers

BufferedReader in = new BufferedReader(new FileReader("<Filename>")); 

Then, you can use in.readLine(); to read a single line at a time. To read until the end, write a while loop as such:

String line; while((line = in.readLine()) != null) {     System.out.println(line); } in.close(); 
like image 143
kevmo314 Avatar answered Sep 30 '22 00:09

kevmo314