Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

read file using scanner in java

// Java Program to illustrate
// reading from Text File
// using Scanner Class
import java.io.File;
import java.util.Scanner;
public class ReadFromFileUsingScanner
{
  public static void main(String[] args) throws Exception
  {
    // pass the path to the file as a parameter
    File file = new File("C:UserspankajDesktop	est.txt");
    Scanner sc = new Scanner(file);
 
    while (sc.hasNextLine())
      System.out.println(sc.nextLine());
  }
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #read #file #scanner #java
ADD COMMENT
Topic
Name
1+4 =