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 get the word by position 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 "get the word by position" Watch "get the word by position" New topic

get the word by position

kumaraswamy adurthi

Joined: Sep 27, 2005
Posts: 11

i have a flat file , in that i have date field , i know the row and column of this date my question is can i get this date by using this column number and row number in java

please help me out

thanks and regards

kumaraswamy adurthi
Santhosh Kumar
Ranch Hand

Joined: Nov 07, 2000
Posts: 242
Java on its own does not provide that type of capability. What you asking for is functionality of DBMS systems. You need to program yourself to read that row and columns.

If you use Oracle, there is a feature called external files where in you can map a flat file as table. So you can query it as any other table.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
If you know the structure of the file precisely, and since you know the row and column, it may be possible to calculate the offset of the date field from the beginning of the file. With that offset you can either use RandomAccessFile or FileInputStream.skip() to access that position directly.

If the fields have varying lengths, and are not padded to fixed length, then this is not possible.
John Calabasas

Joined: Jun 11, 2006
Posts: 17
If its a file with line breaks and delimiters (ex, csv) between column values, I think it will be possible to use a combination of iterating over rows using readLine() and iterating over columns using or String.split() or Regex to achieve the purpose. However this may not be a good approach in case the file is very big.

If the file contains fixed width columns, then you can try using to take you to the appropriate value using some math.

If its a delimited file which is not too big, another option will be to read and populate a 2-dim String Array from the file and read directly using the co-ords.
[ July 04, 2006: Message edited by: John Calabasas ]

I hate quotations. Tell me what you know.
I agree. Here's the link:
subject: get the word by position
It's not a secret anymore!