Let us create a program to scan data from this text file.To scan the file,we will specify the path of the file in the Constructor of the Scanner class.

import java.io.*;
import java.util.Scanner;
public class ScanningFiles
{
    public static void main(String args[])throws IOException
	{
	    Scanner objs=new Scanner(new File("E:/Students data/Data File.txt"));
		int num=1;
		objs.useDelimiter(",");
		while(objs.hasNext()==true)
		{
		   String name=objs.next();
		   System.out.printIn(num+")"+name);
		   num++;
		}
	}
}
Show Buttons
Hide Buttons