java中以字节流的形式读取文件采用的是FileInputStream,将指定路径的文件以字节数组的形式循环读取,代码如下:
public void ReadFileByByte(String path){
try {
int length = 0;
byte[] Buff = new byte[1024];
File file = new File(path);
FileInputStream fis = new FileInputStream(file);
while((length =fis.read(Buff))!=-1){
//对Buff进行处理
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (IOException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}finally{
if(fis!=null){
fis.close();
}
}