0

When I run below lines in Windows command line it does not take the first letter. If I enter 22 it prints only '2'

private static String  readInput() {
    try {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         input = br.readLine();
         System.out.println("input "+input);

   } catch (Exception ioe) {
      System.out.println("Error trying to read your input!");
      ioe.printStackTrace();
   }
}       
user2771655
  • 1,052
  • 3
  • 20
  • 38

3 Answers3

0

Try this.

   while((input = br.readLine()) != null){
         System.out.println("input "+input);
    }
Sky
  • 3,350
  • 2
  • 14
  • 12
0

try like this!

private static String  readInput() {
try {
     DataInputStream in=new DataInputStream(System.in);
     input = in.readLine();
     System.out.println("input "+input);
     return input;
   } catch (Exception ioe) {
      System.out.println("Error trying to read your input!");
      ioe.printStackTrace();
   }
}     
Bala.Raj
  • 1,011
  • 9
  • 18
0

Ok I found the problem. Its not relate to scanner or BufferedReader. All works fine. One of my another back end thread is reading System.in.read();. That's why I always missed first input. Sorry for confusing all of you.

user2771655
  • 1,052
  • 3
  • 20
  • 38