• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to read data from Random Access file

 
Kishor Joshi
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Pie
Posts: 2184
39
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the output? What are you expecting?
 
Kishor Joshi
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Pie
Posts: 2184
39
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would read the docs on random.seek()
 
Kishor Joshi
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Pie
Posts: 2184
39
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried?
 
Kishor Joshi
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49364
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Cambell

Can you please suggest where I am wrong in question posting?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49364
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not doing anything wrong in posting your questions. You are inappropriately calling a random access file a text file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic