• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

input.readLine()

how to use the above function..
i've included the code belows

import java.io.*;

public class Testing
{

      public static void main(String args[]) throws
java.io.IOException
      {

      System.out.println("Enter a name");
      String search = input.readLine();
      System.out.println(search);
      }
}


but when run they will show that can't resolve symbol at the "input" word....

how to actually use the method?

0
yuen_jk
Asked:
yuen_jk
  • 2
1 Solution
 
MogalManicCommented:
the class input does not exist in the main function.  Try adding the following on the 1st line of the main function:
        BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
This will read from the standard input and then buffer the results (the BufferedReader class has the readLine() method)
0
 
Ralf KlattPrincipal ConsultantCommented:
Hi,

MogalManic is right with "BufferedReader" ... but you shouldn' place it on the 1st line of the main function ... I'd suggest doing it that way:

import java.io.*;

public class Testing
{
     static BufferedReader input = new BufferedReader (new InputStreamReader(System.in),1);
     /* the buffer is set to 1 beacuse of a known bug in Windows with JDK 1.1.3. and onwards! */

     public static void main(String args[]) throws java.io.IOException
     {
          System.out.println("Enter a name");
          String search = input.readLine();
          System.out.println(search);
     }
}


Best regards,
Raisor
0
 
Ralf KlattPrincipal ConsultantCommented:
Hi,

I think that I've added a small but not really unimportant information to this question.

My suggestion would be 75% MogalManic and 25% Raisor ...


Best regards,
Raisor
0
 
VenabiliCommented:
Raisor,

MogalManic's solution is working just fine... no problems.. at least I had no troubles with it last 5 years :)

Venabili
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now