• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need urgent help in reading files

 
Abhi Chat
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:-

Header:

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 line..is 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...

thanks

abhishek
 
Inuka Vincit
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this assignment you dont use tokenization to read the file. Many here use the RandomAccessFile. Since we know the size of the fields as specified by the assignment just use the read(byte[])(where the size of the byte array specifies how much to read) and readUnsignedShort(to read record number etc..) methods. Instead of using your own file use file provided in the assignment.Its quite simple, took about 30minutes of messing around to spit out the data file correctly.
 
James Clinton
Ranch Hand
Posts: 190
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic