// Open the fileFileInputStream fstream = new FileInputStream("textfile.txt");BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
//Read File Line By Linewhile ((strLine = br.readLine()) != null) {// Print the content on the consoleSystem.out.println (strLine);}
//Close the input streamfstream.close();
try(BufferedReader br = new BufferedReader(new FileReader(file))) {for(String line; (line = br.readLine()) != null; ) {// process the line.}// line is not visible here.}
import java.io.File;import java.io.FileNotFoundException;import java.util.Scanner;public static void readText throws FileNotFoundException {Scanner scan = new Scanner(new File("samplefilename.txt"));while(scan.hasNextLine()){String line = scan.nextLine();//Here you can manipulate the string the way you want}}
import java.io.*;import java.util.Scanner;import java.io.FileNotFoundException;
public class readByLine{public readByLine() throws FileNotFoundException{Scanner linReader = new Scanner(new File("dataFile.txt"));
while (linReader.hasNext()){String line = linReader.nextLine();System.out.println(line);}linReader.close();
}
public static void main(String args[]) throws FileNotFoundException{new readByLine();}}