Reading in chunks of data



Hi,
I'm reading up on the use of the RandomAccessFile (and other file I/O)
classes in Java but I haven't found anything that can help me. Is
there any way to read in data structured in a text file, as follows:

Apr 10
"The Book of the Dead"
£17.95
Apr 13
"Unconvention Highlights"
£4.99
Apr 14
"Miserable Quotients"
£0.02

etc. etc.

So that I can do the following (in pseudo code):
read first three lines: first line assigned to date value, second to
book title, third to cost variable
read next three lines: first line assigned to date value, second to
book title, third to cost variable
etc.

The only other way I thought about doing it is to read in the file
line-by-line, but, by using line counting
and some arithmetic with modulo operators (?), know that the 1st, 4th,
7th lines are date values,
lines 2, 5 and 8 are titles etc., but this seems fiddly. There must be
an easy way to do this...

With best wishes

Paul
.



Relevant Pages

  • Re: Reading in chunks of data
    ... I'm reading up on the use of the RandomAccessFile (and other file I/O) ... classes in Java but I haven't found anything that can help me. ...
    (comp.lang.java.programmer)
  • Re: how to wait for socket communications
    ... actually at this point I am ready to try out your file I/O suggestion. ... The picture information is an unsigned char*, with first all the red values ... the JVM when the Java program gets closed, and ending up with memory leaks. ... to use socket communication between my C++ program and my Java program. ...
    (microsoft.public.win32.programmer.networks)
  • Re: how to wait for socket communications
    ... actually at this point I am ready to try out your file I/O suggestion. ... the JVM when the Java program gets closed, and ending up with memory leaks. ... to use socket communication between my C++ program and my Java program. ... int sockfd; ...
    (microsoft.public.win32.programmer.networks)
  • Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
    ... >> A few months ago I had an introductory class on Java programming. ... reading from console can be done via a call to ... just one character at a time). ... Stream reader, or an HTTP Input Stream reader, or an Audio Input Stream ...
    (comp.lang.cobol)
  • Re: Doing one last thing to a WeakReference
    ... Too bad Java doesn't provide it. ... I have some class that reads image files. ... the rest of the code will use the various methods of ImageInfo in an arbitrary order. ... The first method called creates the SoftChunkyByteBuffer and, after creation, it (and the RandomAccessFile it uses) sticks around. ...
    (comp.lang.java.programmer)