Program to Read text entered by user in console using DataInputStream in java file IO







Program to Read text entered by user in console using DataInputStream in java file IO >







import java.io.DataInputStream;
import java.io.IOException;
/** JavaMadeSoEasy.com */
public class ReadFromUsersInput {
   public static void main(String...args) {
         
          //will wait for user to type some text and press enter
          DataInputStream dis = null;
         
          try {
          System.out.println("Type some text and press enter...");
         
          dis=new DataInputStream(System.in);
         
          char ch;
                 while((ch=(char)dis.read())!=0) {
                       System.out.print(ch); //Display text typed by user in console
                 }
          } catch (IOException e) {
                 e.printStackTrace();
          }
         
          finally {
                 try {
                       if (dis != null)
                              dis.close(); //close DataInputStream
                 } catch (IOException e) {
                       e.printStackTrace();
                 }
          }
         
         
   }
}
/*OUTPUT
Type some text and press enter...
my name is Ankit
my name is Ankit
*/


RELATED LINKS>

Read text entered by use in consoler using BufferedReader's readLine() method in java file IO

Program to Read text entered by use in console using java.util.Scanner

Program to Read text entered by user in console till some special character (let's say @) in java

Program to Create Directory - Single and multiple (i.e. parent and child directories) in java file IO


eEdit
Must read for you :