Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Tue, 19 Jul 2005 17:14:58 GMT
"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
.
- References:
- Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Oliver Wong
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Oliver Wong
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: docdwarf
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Chuck Stevens
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: docdwarf
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Oliver Wong
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Pete Dashwood
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Howard Brazee
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Pete Dashwood
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Michael Mattias
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Pete Dashwood
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Howard Brazee
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Michael Mattias
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Howard Brazee
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Michael Mattias
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Howard Brazee
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Pete Dashwood
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Arnold Trembley
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Howard Brazee
- Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- Prev by Date: Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- Next by Date: Re: Called Module with File Access - where to Close
- Previous by thread: Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- Next by thread: Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- Index(es):
Relevant Pages
|