Friday 19 August 2016

Java Tutorial : Java IO (Scanner class - Read file data)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=kdJO4miGfro&list=UUhwKlOVR041tngjerWxVccw

myfile.txt
Dave went to London
Peter gone to Japan
Juli went to USA
ScannerDemo.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

/*
 *  Scanner reads file. 
 */
public class ScannerDemo
{

    public static void main(String[] args) throws FileNotFoundException
    {
        Scanner scanner = null;
        try
        {
            File file = new File("myfile.txt");
            scanner = new Scanner(file);

            while (scanner.hasNext())
            {
                String strValue = scanner.nextLine();
                System.out.println(strValue);
            }

        }
        finally
        {
            if (scanner != null)
            {
                scanner.close();
            }
        }
    }
}
Output
Dave went to London
Peter gone to Japan
Juli went to USA

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_Scanner_file_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/JavaIODemo_Scanner_file_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/16638d65b46bec1088dab744ba69a31424c4a14f/BasicJava/JavaIODemo_Scanner_file_App/?at=master

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment