• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RANDOMACCESSFILE

 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.io.*;
public class lapore
{
public static void main(String[]args)throws IOException
{
RandomAccessFile file=new RandomAccessFile("test.txt","rw");
file.writeBoolean(true);
file.writeInt(12345);
file.writeInt(7890);
file.writeLong(1000000);
file.writeInt(777);
file.writeFloat(.001f);
file.seek(5);
System.out.println(file.readInt());
file.close();
}
}
Why the above given code is throwing an answer 7890, why not 777, please throw some light on it.?
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
seek(5), means seek the 4th. byte, that is why answer is 7890.
Remember true is 1 byte, int is 4 byte, long is 8 byte.
So, to read 777, have to seek(13).
 
reply
    Bookmark Topic Watch Topic
  • New Topic