xxxxxxxxxx
import java.io.*;
public class openFile {
public static void main(String[] args) {
try{
File file = new File("C:\\file.txt");
}catch(Exception e){
e.printStackTrace();
}
}
}
xxxxxxxxxx
File myFile = new File("filename.txt");
Scanner myReader = new Scanner(myFile);
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
}
myReader.close();
xxxxxxxxxx
try (Stream<String> stream = Files.lines(Paths.get(String.valueOf(new File("yourFile.txt"))))) {
stream.forEach(System.out::println);
} catch (IOException e) {
e.printStackTrace();
}