0

I use java 6 method readByte() from class randomAccessFile to read text files on linux x64.

I'm looking the end of text line by finding

 "0xD" or "0xA" 

at the end.

My question is : in case operating system will switch to x32 , will the find still work ?

Maybe better to find characters at the end of text line , like

 "\n" 

and not bytes ?

Toren
  • 6,648
  • 12
  • 41
  • 62

1 Answers1

0

Whether you use a 64-bit JVM or a 32-bit JVM the contents of the file don't change so you are looking for the same thing. RandomAccessFile is designed for binary files and so you can only read bytes, not characters. You have to do the translation from bytes to characters.

In short, you read the same bytes in either case and talking about characters is just down to how you see them as characters, only bytes are meaningful.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • thanks for fast answer , question is if byte size on x32 same as x64 ? so when JVM changes I can safely find "0xD" and "0xA" at the end of line ? and my code work as I need – Toren Jan 07 '14 at 10:53
  • 1
    @Toren a byte is always a byte at the machine level. Even if it were not, Java defines a byte is always a signed 8-bit value. e.g. an `int` is always signed 32-bit even on a 64-bit JVM. – Peter Lawrey Jan 07 '14 at 11:11