
public static void bytesToFile(byte[] buffer, final String filePath) throws IOException { File file = ew File(filePath); File fileParent = file.getParentFile(); if (!fileParent.exists()) { fileParent.mkdirs(); OutputStream output = null; BufferedOutputStream bufferedOutput = null; try { output = new FileOutputStream(file); bufferedOutput = new BufferedOutputStream(output); bufferedOutput.write(buffer); } finally { if (null != bufferedOutput) { bufferedOutput.close(); } if (null != output) { output.close(); } } } } 1 BBCCBB 2020-06-09 11:29:26 +08:00 catch 一下看报啥异常. 另外你这代码可以用 try-with-resource 来简化一下. == |
2 dallaslu 2020-06-09 12:13:25 +08:00 会不会是权限问题 |
3 linjian OP 权限是有的。没有任何报错信息,各种尝试之后发现文件如果已经下载过一次,第二次下载执行到 output = new FileOutputStream(file);就闪退,BufferedOutputStream 正常写不是可以覆盖文件原来内容的吗? |
5 calloc 2020-06-09 15:59:11 +08:00 via iPhone 代码有问题,一个文件只需要 close 一次 |