Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

read file java line

package com.journaldev.readfileslinebyline;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class ReadFileLineByLineUsingBufferedReader {

	public static void main(String[] args) {
		BufferedReader reader;
		try {
			reader = new BufferedReader(new FileReader(
					"/Users/pankaj/Downloads/myfile.txt"));
			String line = reader.readLine();
			while (line != null) {
				System.out.println(line);
				// read next line
				line = reader.readLine();
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
Source by www.journaldev.com #
 
PREVIOUS NEXT
Tagged: #read #file #java #line
ADD COMMENT
Topic
Name
9+1 =