简体   繁体   中英

Writing a string to file as a byte in Java

I'm having a little trouble writing the values I want to a file. I'm using RandomAccessFile to output the values. What I want to do is take a string (which contains two digits, 0-9) and write them to a file as a byte. I've tried a few different ways but cannot seem to nail it.. Any help?

 String yourString = "0F"; 
 byte aByte = Byte.parseByte(yourString, 16);

And then just write that byte in your file and you are all set.

NOTE: That 16 is the radix, use 10 for decimal, 16 for hex

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM