Chapter 14: I/O
14.6 Interacting with Users

14.6 Interacting with Users

Concept

  • To test the program written in this section, we have to run the program from the terminal.
  • When the JVM is started from an interactive command line, the input and output of the Java program are not being sent to or received from somewhere else.

Important methods

f

Reading and writing data

public Reader reader()
public PrintWriter writer()

Formatting console data

// PrintStream (binary data)
public PrintStream format(String format, Object... args)
public PrintStream format(Locale loc, String format, Object... args)
 
// PrintWriter (regular text data)
public PrintWriter format(String format, Object... args)
public PrintWriter format(Locale loc, String format, Object... args)
 
// To make C developers feel more at home
public Console printf(String format, Object... args)

Reading console data

// Normal text 
public String readLine()
public String readLine(String fmt, Object... args)
 
// Password text (will be hidden)
public char[] readPassword()
public char[] readPassword(String fmt, Object... args)