我有一个文件,文件的开头包含一些纯文本,结尾处是二进制内容.二进制内容的大小由我阅读的纯文本行之一确定.
我使用BufferedReader读取单独的行,但是它没有公开任何方法来读取字节数组. DataInputStream的readUTF不会一直读到行尾,不建议使用readLine方法.
使用基础FileInputStream读取将返回空字节数组.关于如何进行此操作有什么建议吗?
private DOTDataInfo parseFile(InputStream stream) throws IOException{
DOTDataInfo info = new DOTDataInfo();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
int binSize = 0;
String line;
while((line = reader.readLine()) != null){
if(line.length() == 0)
break;
DOTProperty prop = parseProperty(line);
info.getProperties().add(prop);
if(prop.getName().equals("ContentSize"))
binSize = Integer.parseInt(prop.getValue());
}
byte[] content = new byte[binSize];
stream.read(content); //Its all empty now. If I use a DataInputStream instead, its got the values from the file
return info;
}