java how to read a text file code example
Example 1: reading from a text file in java
public static void main(String[] args) throws Exception
{
FileReader fr = new FileReader("C:\\Users\\pankaj\\Desktop\\test.txt");
int i;
while ((i=fr.read()) != -1)
System.out.print((char) i);
}
Example 2: java how to read a text file
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
class Scratch{
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(new File("filename"));
input.next();
input.nextLine();
input.nextBoolean();
input.nextInt();
input.nextDouble();
...
}
}