Answers for "how to open a file and read line by line in java"

1

java read lines from file

Scanner sc = null;
        try {
            File file = new File("myfile.txt"); // java.io.File
            sc = new Scanner(file);     // java.util.Scanner
            String line;
            while (sc.hasNextLine()) {
              line = sc.nextLine();
              // process the line
            }
          }
          catch(FileNotFoundException e)
          {
              e.printStackTrace();
          }
          finally {
            if (sc != null) sc.close();
          }
Posted by: Guest on March-12-2020

Code answers related to "how to open a file and read line by line in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language