[英]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....例如......我的字节数组以值 7、17、118、7....
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.一次读取文件 8 个字符并使用
Integer.parseInt(chars, 2)
其中chars
是您作为字符串读取的 8 个字符。 Repeat until the file is completely read.重复直到文件被完全读取。
use the input stream使用输入 stream
InputStream is = new FileInputStream(new File("filen.ame"));
is.read(byte[] b, 0, len(file))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.