Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. public static void main(String args[]) throws FileNotFoundException {
  2.  
  3. System.out.print("Enter the file name with its location and extension : ");
  4. Scanner input = new Scanner(System.in);
  5. File text = new File(input.nextLine());
  6.  
  7. //Creating Scanner instnace to read File in Java
  8. Scanner scnr = new Scanner(text);
  9.  
  10. //Reading each line of file using Scanner class
  11. int lineNumber = 1;
  12.  
  13. while(scnr.hasNextLine()){
  14. String line = scnr.nextLine();
  15. System.out.println("line " + lineNumber + " :" + line);
  16. lineNumber++;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement