Re: How can I use class FileInputStream as a reverse of FileOutputStream?
From: Jean-Benoit MORLA (jbmorla_at_tiscali.fr)
Date: 11/05/04
- Next message: David Alex Lamb: "comp.lang.java.{help,programmer} - what they're for (mini-FAQ 2004-10-08)"
- Previous message: bugbear: "Re: Regular Expression Creator"
- In reply to: Thomas Weidenfeller: "Re: How can I use class FileInputStream as a reverse of FileOutputStream?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 5 Nov 2004 02:11:09 -0800
Thomas Weidenfeller <nobody@ericsson.invalid> wrote in message news:<cmdco1$2fm$1@newstree.wise.edt.ericsson.se>...
> Jean-Benoit MORLA wrote:
> > So I searched the Sun Java 1.5 site for the io package and
> > I found the FileInputStream class.
> > However it states that "FileInputStream is meant for reading streams
> > of raw bytes such as image data."
> > It is advised to use FileReader instead.
> > So what should I do:
> > - try method read( byte[] b ) with b the length of the array of bytes
> > ( but I don't see how to set b for each new line of the .txt file )
> > - Stick to FileReader and FileWriter
>
> Java indeed makes a distinction between characters and bytes (as
> opposite to what is e.g. common in C). Java also handles different
> encodings (an encoding specifies how characters are represented as
> bytes). When you use the I/O classes intended for reading/writing text,
> the conversion (decoding/encoding) is done by Java for you, which is
> usually a good thing.
>
> So, if
>
> * you want to read text data and work with it as text, use a Reader of
> some kind.
>
> * you want to write text, and make sure it is indeed ending up in some
> text encoding in the file, use a Writer of some kind.
>
> * you want to read binary data, and don't want the data to get
> interpreted as some text encoding, use some kind of InputStream.
>
> * you want to write binary data, and want to make sure that it is not
> changed due to some text encoding, use some kind of OutputStream.
>
> You can read text files as binary data. This is only useful in some
> special cases, and not a good idea when you really want to deal with
> text. You can also create text files using the binary writing classes.
> But again, this is only useful in very special cases.
>
> /Thomas
>>> Thomas,
>>> Many thanks for your clear reply
>>> I think it's time I look up for the Unicode-dealing classes
>>> Have a nice day
- Next message: David Alex Lamb: "comp.lang.java.{help,programmer} - what they're for (mini-FAQ 2004-10-08)"
- Previous message: bugbear: "Re: Regular Expression Creator"
- In reply to: Thomas Weidenfeller: "Re: How can I use class FileInputStream as a reverse of FileOutputStream?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|