Sunday, 18 December 2022

Read develop a program in which read the file by using scanner class.

  READ A FILE 




import java.util.Scanner;
import java.io.File;

public class file {
  public static void main(String args[]) throws Exception {

    try {
      File x = new File("a.txt");
      Scanner sc = new Scanner(x);
      while (sc.hasNext()) {
        System.out.println(sc.next());
      }
      sc.close();
    } catch (Exception e) {
      System.out.println("Error");
 
    }
}

}


OUTPUT: SSS

No comments:

Post a Comment

GitHub Most Imp Command For Every Developer Learn:

 Top Command for GitHub:  1) git clone 2) git init and git status   3) git add file name  or git add .  4) git commit -m message  5) git rem...