Skip to main content
Copy edited.
Source Link
Peter Mortensen
  • 31.2k
  • 22
  • 110
  • 134

This is basically the exact same as Jesus Ramos' answer, except with File instead of FileReader plus iteration to step through the contents of the file.

Scanner in = new Scanner(new File("filename.txt"));

while (in.hasNext()) { // iteratesIterates each line in the file
    String line = in.nextLine();
    // doDo something with line
}

in.close(); // don'tDon't forget to close resource leaks

... throws FileNotFoundException

This is basically the exact same as Jesus Ramos' answer, except with File instead of FileReader plus iteration to step through the contents of the file.

Scanner in = new Scanner(new File("filename.txt"));

while (in.hasNext()) { // iterates each line in the file
    String line = in.nextLine();
    // do something with line
}

in.close(); // don't forget to close resource leaks

... throws FileNotFoundException

This is basically the exact same as Jesus Ramos' answer, except with File instead of FileReader plus iteration to step through the contents of the file.

Scanner in = new Scanner(new File("filename.txt"));

while (in.hasNext()) { // Iterates each line in the file
    String line = in.nextLine();
    // Do something with line
}

in.close(); // Don't forget to close resource leaks

... throws FileNotFoundException

Wrong exception name.
Source Link
ThisClark
  • 14.9k
  • 11
  • 74
  • 103

This is basically the exact same as Jesus Ramos' answer, except with File instead of FileReader plus iteration to step through the contents of the file.

Scanner in = new Scanner(new File("filename.txt"));

while (in.hasNext()) { // iterates each line in the file
    String line = in.nextLine();
    // do something with line
} 

in.close(); // don't forget to close resource leaks

... throws FileNotFoundException

This is basically the exact same as Jesus Ramos' answer, except with File instead of FileReader plus iteration to step through the contents of the file.

Scanner in = new Scanner(new File("filename.txt"));

while (in.hasNext()) { // iterates each line in the file
    String line = in.nextLine();
    // do something with line
}

... throws FileNotFoundException

This is basically the exact same as Jesus Ramos' answer, except with File instead of FileReader plus iteration to step through the contents of the file.

Scanner in = new Scanner(new File("filename.txt"));

while (in.hasNext()) { // iterates each line in the file
    String line = in.nextLine();
    // do something with line
} 

in.close(); // don't forget to close resource leaks

... throws FileNotFoundException

This is basically the exact same as Jesus Ramos' answer, except with File instead of FileReader plus iteration to step through the contents of the file.

Scanner in = new Scanner(new File("filename.txt"));

while (in.hasNext()) { // iterates each line in the file
    String line = in.nextLine();
    // do something with line
}

... throws IOExceptionFileNotFoundException

This is basically the exact same as Jesus Ramos' answer, except with File instead of FileReader plus iteration to step through the contents of the file.

Scanner in = new Scanner(new File("filename.txt"));

while (in.hasNext()) { // iterates each line in the file
    String line = in.nextLine();
    // do something with line
}

... throws IOException

This is basically the exact same as Jesus Ramos' answer, except with File instead of FileReader plus iteration to step through the contents of the file.

Scanner in = new Scanner(new File("filename.txt"));

while (in.hasNext()) { // iterates each line in the file
    String line = in.nextLine();
    // do something with line
}

... throws FileNotFoundException

added 35 characters in body
Source Link
ThisClark
  • 14.9k
  • 11
  • 74
  • 103
Loading
added 165 characters in body
Source Link
ThisClark
  • 14.9k
  • 11
  • 74
  • 103
Loading
Source Link
ThisClark
  • 14.9k
  • 11
  • 74
  • 103
Loading