Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String args[]) throws FileNotFoundException {
- System.out.print("Enter the file name with its location and extension : ");
- Scanner input = new Scanner(System.in);
- File text = new File(input.nextLine());
- //Creating Scanner instnace to read File in Java
- Scanner scnr = new Scanner(text);
- //Reading each line of file using Scanner class
- int lineNumber = 1;
- while(scnr.hasNextLine()){
- String line = scnr.nextLine();
- System.out.println("line " + lineNumber + " :" + line);
- lineNumber++;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement