1 public static void main(String[] args) throws Exception
2 {
3 // pass the path to the file as a parameter
4 FileReader fr = new FileReader("C:\\Users\\pankaj\\Desktop\\test.txt");
5
6 int i;
7 while ((i=fr.read()) != -1)
8 System.out.print((char) i);
9 }
1import java.io.File;
2import java.io.FileNotFoundException;
3import java.util.Scanner;
4
5class Scratch{
6 public static void main(String[] args) throws FileNotFoundException {
7 Scanner input = new Scanner(new File("filename"));
8 input.next(); //returns next String
9 input.nextLine(); //returns next Line
10 input.nextBoolean();//returns next Boolean
11 input.nextInt(); //returns next Int
12 input.nextDouble(); //returns next double
13 ...
14 }
15}