Harish Chandra
February 25th, 2000, 06:05 AM
What is the end of InputStream in DOS? I am running the following program in MS-DOS prompt under Windows 95 (code picked up from "The Java Programming Language" by Ken Arnold and James Gosling). If I press CTRL+C or CTRL+Z, it ends the program without printing the output. I have tried all other control characters but could not determine end of the input.
Here is the code:
/* CountBytes.java
Illustrates the use of InputStream.
From: The Java Programming Language, pg 228-229.
*/
import java.io.*;
class CountBytes {
public static void main (String [] args) throws IOException {
InputStream in;
// Don't know what key to press to mark the end-of-input from the DOS prompt.
if (args.length == 0)
in = System.in;
else
in = new FileInputStream (args [0]);
int total = 0;
while (in.read () != -1)
total ++;
System.out.println (total + " bytes.");
}
}
Here is the code:
/* CountBytes.java
Illustrates the use of InputStream.
From: The Java Programming Language, pg 228-229.
*/
import java.io.*;
class CountBytes {
public static void main (String [] args) throws IOException {
InputStream in;
// Don't know what key to press to mark the end-of-input from the DOS prompt.
if (args.length == 0)
in = System.in;
else
in = new FileInputStream (args [0]);
int total = 0;
while (in.read () != -1)
total ++;
System.out.println (total + " bytes.");
}
}