Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args)
- {
- Scanner fn = new Scanner(System.in);
- System.out.println("Enter the file name");
- String name = fn.next();
- try {
- File Obj = new File(name);
- Scanner Reader = new Scanner(Obj);
- while (Reader.hasNextLine()) {
- String data = Reader.nextLine();
- System.out.println(data);
- }
- Reader.close();
- }
- catch (FileNotFoundException e) {
- System.out.println("An error has occurred.");
- e.printStackTrace();
- }
- }
- }
- /*
- Enter the file name
- user.txt
- id : 1
- Name : Suresh
- Address : 12 Rajesh Nagar MP
- phone no : 123
- */
Add Comment
Please, Sign In to add comment