Tuesday, 16 August 2016

Java Tutorial : Java IO (InputStreamReader - Read from keyboard)



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

Click the below Image to Enlarge
Java Tutorial : Java IO (InputStreamReader - Read from keyboard) 
InputStreamReaderDemo.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class InputStreamReaderDemo
{

    public static void main(String[] args) throws IOException
    {
        InputStreamReaderDemo inputStreamReaderDemo = new InputStreamReaderDemo();
        inputStreamReaderDemo.readData();
    }

    private void readData() throws IOException
    {
        InputStreamReader inputStreamReader = null;
        BufferedReader bufferedReader = null;
        System.out.print("Enter your name : ");
        try
        {
            inputStreamReader = new InputStreamReader(System.in);
            /*
             * We are connecting the BufferedReader stream
             * with the InputStreamReader stream for reading
             * the line by line data from the keyboard.
             */
            bufferedReader = new BufferedReader(inputStreamReader);
            String name = bufferedReader.readLine();
            System.out.println("Welcome " + name);
        }
        finally
        {
            if (inputStreamReader != null)
            {
                inputStreamReader.close();
            }
            if (bufferedReader != null)
            {
                bufferedReader.close();
            }
        }

    }

}
Output
Enter your name : Peter
Welcome Peter

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/ebaa49adbc935437412c3f95a1070f272f5231dd/BasicJava/JavaIODemo_InputStreamReader_Read_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

    Google+ Followers

    Google+ Badge