方式一:public byte [] readBytes(String filePath) {
byte [] bt = null;
FileInputStream fis = null;
try {
fis = new FileInputStream(filePath);
bt = new byte[fis.available()];
fis.read(bt);
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
return bt;
}
方式二:public byte [] readBytes(String filePath) {
byte [] bt = null;
FileInputStream fis = null;
try {
fis = new FileInputStream(filePath);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bt = new byte [1024];
while (fis.read(bt) != -1) {
baos.write(bt);
}
baos.close();
fis.close();
bt = baos.toByteArray();
} catch (IOException e) {
e.printStackTrace();
}
return bt;
}请问这两种方式那种更好,是否与文件大小有关?