Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.nio.file.Paths;
- import java.util.Scanner;
- public class PrintingAFile {
- public static void main(String[] args) {
- try ( Scanner scanner = new Scanner(Paths.get("data.txt"))) {
- // we read the file until all lines have been read
- while (scanner.hasNextLine()) {
- // we read one line
- String row = scanner.nextLine();
- // we print the line that we read
- System.out.println("Whats goingon ?");
- System.out.println(row);
- }
- } catch (Exception e) {
- System.out.println("Error: " + e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement