1try(BufferedReader br = new BufferedReader(new FileReader("file.txt"))) {
2 StringBuilder sb = new StringBuilder();
3 String line = br.readLine();
4
5 while (line != null) {
6 sb.append(line);
7 sb.append(System.lineSeparator());
8 line = br.readLine();
9 }
10 String everything = sb.toString();
11}
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 }