Save keyboard input with BufferedInputStream : BufferedInputStream « File « Java Tutorial






import java.io.BufferedInputStream;
import java.io.IOException;

public class ConsoleInput {
  public static String readLine() {
    StringBuffer response = new StringBuffer();
    try {
      BufferedInputStream buff = new BufferedInputStream(System.in);
      int in = 0;
      char inChar;
      do {
        in = buff.read();
        inChar = (char) in;
        if ((in != -1) & (in != '\n') & (in != '\r')) {
          response.append(inChar);
        }
      } while ((in != -1) & (inChar != '\n') & (in != '\r'));
      buff.close();
      return response.toString();
    } catch (IOException e) {
      System.out.println("Exception: " + e.getMessage());
      return null;
    }
  }

  public static void main(String[] arguments) {
    System.out.print("\nWhat is your name? ");
    String input = ConsoleInput.readLine();
    System.out.println("\nHello, " + input);
  }
}








11.9.BufferedInputStream
11.9.1.BufferedInputStream
11.9.2.Buffered Stream Copier
11.9.3.Read from file with BufferedInputStream
11.9.4.Read File in String Using Java BufferedInputStream Example
11.9.5.Read File Using Java BufferedInputStream Example
11.9.6.Use buffered streams to copy a file
11.9.7.Import a file of exported preference data.
11.9.8.Save keyboard input with BufferedInputStream