A text file.
Recall that a text file is just like any file, except that its bytes must represent characters and a few control characters. Java programs can use other types of file as input, but this chapter will only discuss text files as input.
Here is a program that can be used with input redirection. Notice that it is written to do input from the keyboard:
class Echo { public static void main ( String[] args ) throws IOException { String line; BufferedReader stdin = new BufferedReader( new InputStreamReader( System.in ) ); System.out.println("Enter your input:"); line = stdin.readLine(); System.out.println( "You typed: " + line ); } }
Here is how the program ordinarily works:
C:\users\default\JavaLessons>java Echo Enter your input: This came from the keyboard You typed: This came from the keyboard D:\users\default\JavaLessons>