• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem encoding DB file

 
Nina Binde
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I just wrote a simple java class to encode the DB file. This is the code I have:
RandomAccessFile raf = new RandomAccessFile("db-2x2.db", "rw");
byte b[] = new byte[10];
raf.read(b);
String str = new String(b, "ISO-8859-1");
System.out.println("The first 10 bytes of the file is "+str);

The str printed out is some strange characters like faces, etc..What am I doing wrong here?
Thanks for helping..
 
John Stone
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are probably modifying file in another directory. Try to invoke your program from command line (in directory where your file is) or provide full path to file.
 
Jason Moors
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nina,

I think the problem is that you are converting all the bytes to characters.


Start of file
4 byte numeric, magic cookie value. Identifies this as a data file
4 byte numeric, total overall length in bytes of each record
2 byte numeric, number of fields in each record


So you should use :



Regards
Jason
 
Nina Binde
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys for your reply. Jason, you are right. I should have read the specs more clearly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic