Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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();
          }
Source by stackabuse.com #
 
PREVIOUS NEXT
Tagged: #java #read #lines #file
ADD COMMENT
Topic
Name
8+1 =