1import java.io.*;
2
3public class openFile {
4
5 public static void main(String[] args) {
6 try{
7 File file = new File("C:\\file.txt");
8 }catch(Exception e){
9 e.printStackTrace();
10 }
11 }
12
13}
1try (Stream<String> stream = Files.lines(Paths.get(String.valueOf(new File("yourFile.txt"))))) {
2 stream.forEach(System.out::println);
3} catch (IOException e) {
4 e.printStackTrace();
5}