简体   繁体   中英

Convert a binary file into a byte array in java?

I've previously converted a byte array into a file conataining the binary equivalents of all the values in that byte array. Now how do do I convert those binary values back into a byte array??

Like for example...my byte array starts with values 7, 17, 118, 7.... And my text file conatining the binary values shows 00000111000100010111011000000111....

Read the file 8 characters at a time and use Integer.parseInt(chars, 2) where chars is the 8 characters you read in as a String. Repeat until the file is completely read.

use the input stream

InputStream is = new FileInputStream(new File("filen.ame"));
is.read(byte[] b, 0, len(file))

Input Stream Documentation

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