下面的decodingValue是priting 63而不是157.从二进制文件中读取的500个值只对该值有效,问题仍然存在
import java.nio.ByteBuffer;
import java.nio.ShortBuffer;
byte[] dataBlockBytes;
decodedSOR = readFileAsString("binary filepath");
int index = 0;
dataBlockBytes = decodedSOR.substring(index,index+14).getBytes();
int decodedValue= ByteBuffer.wrap(dataBlockBytes,2,4).order(ByteOrder.LITTLE_ENDIAN).getInt()
/**
* To read File and return as String
* @param filePath
* @return
* @throws IOException
*/
public String readFileAsString(String filePath) throws IOException {
StringBuffer fileData = new StringBuffer();
BufferedReader reader = new BufferedReader(
new FileReader(filePath));
char[] buf = new char[1024];
int numRead=0;
while((numRead=reader.read(buf)) != -1){
String readData = String.valueOf(buf, 0, numRead);
fileData.append(readData);
}
reader.close();
//System.out.println("fileData.toString()===> "+fileData.toString());
return fileData.toString();
}