And lo, the chronicles report that Dimitris Vyzovitis spake thusly unto the masses:
> 
> > less and more both worked, but you are right, it is zero length. But
> > why should that prevent Java from reading it (in fact I see it that someon
> > else has tried it and succeeded). After all, stdin is zero length before
> > you put anything into it. As long as reading does not get and end-of-file
> > you should be fine.
> >
> 
> Right, but it only works with a FileReader, curiously enough.
> This makes me  wonder on the implementation diffs between a FileReader and
> FileInputStream.
> Does anybody have a clue on that?
> 
> Dimitris
> 
> 


Where did you get this idea? FileReader and FileInputStream both work
the same. Here's some code I whipped up:

/* ********************************************************************** */
import java.io.*;

public class testProc {

    public static void main( String args[] ) {
        try {
            FileInputStream in1 = new FileInputStream( "/proc/version" );
            int ch = in1.read();
            while( ch != -1 ) {
                System.out.print( (char) ch );
                ch = in1.read();
            }
            in1.close();
        }
        catch( Exception e ) {
            e.printStackTrace();
        }
        System.out.println( "\nDone with FileInputStream." );
        
        
        try {
            FileReader in2 = new FileReader( "/proc/version" );
            int ch = in2.read();
            while( ch != -1 ) {
                System.out.print( (char) ch );
                ch = in2.read();
            }
        }
        catch( Exception e ) {
            e.printStackTrace();
        }
        System.out.println( "\nDone with FileReader." );
    }
}
/* ********************************************************************** */

Here's the output of the resultant program:

Linux version 2.2.0 (root@usaagaudio) (gcc version 2.7.2.3) #2 SMP Fri Jan 29 13:47:39 
EST 1999

Done with FileInputStream.
Linux version 2.2.0 (root@usaagaudio) (gcc version 2.7.2.3) #2 SMP Fri Jan 29 13:47:39 
EST 1999

Done with FileReader.


BTW, according to "Java in a Nutshell, 2nd Edition": 

"The FileReader constructor internally creates a FileInputStream to read bytes
from the specified file, and uses the functionality of its superclass,
InputStreamReader, to convert those bytes from characters in the local
encoding to the Unicode characters used by Java."

So it would seem that if a FileInputStream can do it, so can a FileReader.

-- 

¤--------------------------------------------------------------------¤
| Aaron Gaudio                   mailto:[EMAIL PROTECTED] |
|                    http://www.rit.edu/~adg1653/                    |
¤--------------------------------------------------------------------¤
|      "The fool finds ignorance all around him.                     |
|          The wise man finds ignorance within."                     |
¤--------------------------------------------------------------------¤

Use of any of my email addresses is subject to the terms found at
http://www.rit.edu/~adg1653/email.shtml. By using any of my addresses, you
agree to be bound by the terms therein.

Reply via email to