File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes reading from files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "reading from files " Watch "reading from files " New topic

reading from files

Abhi Chat
Ranch Hand

Joined: Oct 10, 2004
Posts: 57
i have just started to prepare for scjd and as someone said started to make short programs on the diffrents java APIS.

one of them was:

Use an IO program to create a file with a header and data. For example:-


FileID, Field1Name, Field1Length, Field2Name, Field2Length etc... ie

"Steven My Address 1 21"
"Fred His Address 2 69"
"Mary Her Address 3 12" etc..

Now Im tryin to write a mini-app that can read the header, figure out what data to expect and then read through the data parsing each record into 3 fields and print them to the screen?

what im tryin to do is generalize the cases and not use any concept that each feild may of some size.

But in doing that Im able to read the data through the header using buffered
Header and readLine. But when i try to read the data by saving in reae readLine I wont know its a letter or a digit. Also how do i tokenize it..if I dont know the lenghts and i dont use a marker such as coma or whatever...
could i use Character.letteror digit...

Also if I use datastream to read the data..then i can find out its letter or digit but how will i find the end of line and then go to next there
somethin like readline in datastream..also how do i find the tokens...

Is there something like help in java like c or c++ where we can find all the functions...



[EJFH: Everyone thinks their question is urgent and needs help; no need to put that in your subject. ]
[ October 19, 2004: Message edited by: Ernest Friedman-Hill ]

SCJP 1.4<br />Preparing for <br />SCJD and SCWCD
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923


[ October 13, 2004: Message edited by: Stefan Wagner ]
[ October 13, 2004: Message edited by: Stefan Wagner ]
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

If you did not download the API docs, as Stefan suggests, they are available online here. There is also the Java Tutorial, which provides explanations and examples.

[How To Ask Questions On JavaRanch]
Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342
I'm amazed that you managed to get SCJP without even knowing about the API doc

SCJP 1.4,
I agree. Here's the link:
subject: reading from files
jQuery in Action, 3rd edition