Discuss / Java / getFileDataAsBytes方法这样写对不对啊?

getFileDataAsBytes方法这样写对不对啊?

Topic source

static byte[] getFileDataAsBytes(File file)throws IOException {

byte[] data;

try (InputStream input1 = new FileInputStream(file);

ByteArrayOutputStream output = new ByteArrayOutputStream())

{

int n;

while ((n = input1.read()) != -1) {

output.write(n);

}

data = output.toByteArray();

}

return data;

}


  • 1

Reply