+ inputStreamToFile fixed.

This commit is contained in:
坏黑 2018-10-30 18:23:56 +08:00
parent cfba114331
commit 289de88b69

View File

@ -144,12 +144,14 @@ public class FileUtils {
* @param file 文件 * @param file 文件
*/ */
public static void inputStreamToFile(InputStream inputStream, File file) { public static void inputStreamToFile(InputStream inputStream, File file) {
try { try (FileOutputStream fos = new FileOutputStream(file) ; BufferedOutputStream bos = new BufferedOutputStream(fos)) {
String text = new String(IO.readFully(inputStream), Charset.forName("utf-8")); byte[] buf = new byte[1024];
FileWriter fileWriter = new FileWriter(FileUtils.createNewFile(file)); int len;
fileWriter.write(text); while((len = inputStream.read(buf)) > 0) {
fileWriter.close(); bos.write(buf, 0, len);
} catch (IOException ignored) { }
bos.flush();
} catch (Exception ignored) {
} }
} }