Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?



"Howard Brazee" <howard@xxxxxxxxxx> wrote in message
news:dbivdd$2u4$1@xxxxxxxxxxxxxxxxxxxxxxx
>> A few months ago I had an introductory class on Java programming. I
>> managed to get through all the in-class assignments, but they never
>> got as far as reading or writing a file, or even accepting user
>> entered data from the screen. I guess that must be covered in the
>> intermediate or advanced class.

For what it's worth, reading from console can be done via a call to
System.in.read(), though returns a byte (more on this later).

> That's my experience as well. Reading and writing files is not a basic
> Java
> function.

Yeah, simple reading and writing to text files is typically more annoying
than in other languages due to the API library's design for streams.

The idea is that you'd use the FileInputStream class to actually open a file
and the data one byte at a time.

Then you'd put the FileInputStream into an InputStreamReader, which will
handle decoding the bytes into characters (using ASCII, EDBIC, Unicode
UTF-8, or whatever encoding scheme you specify).

Then you'd put the InputStreamReader into a BufferedReader, which would
handle buffering the data, and reading a whole line at a time (as opposed to
just one character at a time).

I think Sun chose this system for its flexibility. You could replace the
FileInputStream with something which reads from the console instead of a
file (as in the "System.in" object mentioned above), or with a TCP/IP Input
Stream reader, or an HTTP Input Stream reader, or an Audio Input Stream
reader (for reading bytes from the microphone), and the rest of the code
wouldn't have to change or be aware of where the data is coming from.

For the lazy, Sun also provides a "FileReader" class, which allows you to
just provide a filename, and it'll let you read from that file one character
at a time (you'd still need to BufferedReader to get one line at a time).
The FileReader assumes a default character encoding depending on what
operating system it's running on (which for all the systems I've
encountered, is Unicode UTF-8).

With most projects I've worked with, we don't actually really read plain
text data from files anymore. When I work with files in Java, it's almost
always XML files, and Java has some very powerful support for reading and
writing XML.

- Oliver


.



Relevant Pages

  • Re: asymptote/hyperbola?
    ... He's presenting a character who's talking math. ... So a responsible reading will account for this nonsense in at least one ... Translation is the foundation of every reading. ... >> On your last hermeneutic occasion, you informed us that all the dancer ...
    (rec.arts.books)
  • Re: Update
    ... So my writing isn't making the jumps it could, ... otherwise not particularly good series --the lead character nearly ... The possible interruption was someone betareading one of my books, ... I liked reading the story. ...
    (rec.arts.sf.composition)
  • Recently Read - February, 2006
    ... It's been a busy month with reading taking last place. ... almost as well as Robin McKinley on a so-so day. ... Good vs. Evil breaks out. ... Lt. Eve Dallas is after a cool character this time. ...
    (rec.arts.sf.written)
  • Re: Binary v. Text, why is it faster?
    ... than reading textual data. ... To my understanding, reading a text file is reading in the bytes which correspond to, for example, ASCII character codes. ... Software capable of understanding the particular binary format method of encoding information must be used to interpret the information in a binary formatted file. ...
    (comp.programming)
  • Re: Watchmen?
    ... I'd like to point out that the presence of Kovacs' psychiatrist moved ... Now that I've read (am reading) that thread, ... Usually I get Pinter rather than Joyce. ... character gave a monologue, another character appeared, and they ...
    (rec.arts.comics.dc.universe)