File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to read data from Random Access file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to read data from Random Access file" Watch "How to read data from Random Access file" New topic
Forums: Beginning Java I/O and Streams
Author

How to read data from Random Access file

Kishor Joshi
Ranch Hand

Joined: Sep 24, 2012
Posts: 274
Hi there

I have a random access file stream

I have below code I want to written data that is currently pointed by pointer till the end and display that data on System.out Stream but it is not working my code is



where am I wrong?

although it is returning actual position of pointer in pointer using


Thanks
Knute Snortum
Ranch Hand

Joined: Apr 20, 2013
Posts: 449
    
    5

What's the output? What are you expecting?
Kishor Joshi
Ranch Hand

Joined: Sep 24, 2012
Posts: 274
Problem is sloved basically.

My Pointer is pointing out of file.

I changed value from 300 to 10 and it is displaying all values after that pointer

But My Question is

1)if pointer is 300 is not in my file range why it is not throwing exception?


2)my second question can I read value of specific range in Random Access file I mean there is a start and end index to access a file in Random Access file


Thanks
Knute Snortum
Ranch Hand

Joined: Apr 20, 2013
Posts: 449
    
    5

I would read the docs on random.seek()
Kishor Joshi
Ranch Hand

Joined: Sep 24, 2012
Posts: 274
Yes I can also read using that method seek()

one more thing like read method

If I want to write value at specific position using
write method How I can do that?

suppose at the End,on mid ,or at a specific point.By defult it writes at the starting of file

Thanks
Knute Snortum
Ranch Hand

Joined: Apr 20, 2013
Posts: 449
    
    5

What have you tried?
Kishor Joshi
Ranch Hand

Joined: Sep 24, 2012
Posts: 274
here is few changes I made in my code and its working now





This way it will start writing from pointer 23 and append (2.12) bit on require file


Problem Solved


Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
I shall duplicate this discussion in the IO forum.
Don't call a random access file XYZ.txt. You will get severely confused about it if you come back to it in six months and think it is a text file.
Kishor Joshi
Ranch Hand

Joined: Sep 24, 2012
Posts: 274
Thanks Cambell

Can you please suggest where I am wrong in question posting?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
You are not doing anything wrong in posting your questions. You are inappropriately calling a random access file a text file.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to read data from Random Access file