• Post Reply Bookmark Topic Watch Topic
  • New Topic

RandomAccessFile write bytes  RSS feed

 
Stefan Gerber
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I would like to write a String as a byte array and read it again. Now i have the problem when i wan't read the byte array again and convert it to a string
i don't get the same string. Any suggestion where the fault is?

 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to reset the file pointer to 0. So raf.seek(0L);
 
Stefan Gerber
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that was the problem. I want overwrite the file with some bytes. the existent file has e.g. 20 bytes and new there are only 5 bytes. how can i clean the
rest of the 15 bytes? Is there a way that i can set EOF?
 
Stephan van Hulst
Saloon Keeper
Posts: 7817
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you take a look at RandomAccessFile?
 
Stefan Gerber
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah i have read it. but i missed the setLength part......
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!