CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2000
    Posts
    2

    End of InputStream in DOS?

    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.");
    }
    }



  2. #2
    Join Date
    Nov 1999
    Location
    Tilburg-Breda, Noord-Brabant, The Netherlands
    Posts
    135

    Re: End of InputStream in DOS?

    Hi there,
    Here's a little example that use 'q' to stop the input.

    import java.io.*;

    class BRRead {
    public static void main(String args[])
    throws IOException
    {
    int total = 0;
    char c;
    BufferedReader br = new
    BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter characters, 'q' to quit.");

    // read characters
    do {
    c = (char) br.read();
    total++;
    } while(c != 'q');
    System.out.println (total + " bytes.");
    }
    }




    Greets,
    Jan Meeuwesen.
    ( Don't forget to vote this answer (bottom right) )


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured