From 60b501b7474ba74fbc94760ca4873502d16037c6 Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Sat, 31 Mar 2018 16:26:17 -0400 Subject: [PATCH] Fix for unreliable createNewFile function At one point, this was necessary(?). It appears to be problematic and the root cause of an unnecessary FileNotFoundException. Apache's FileUtils will create the directory and file, if necessary, when using version 1.3+ of the io library. This avoids maintaining workarounds. --- .../java/com/reicast/emulator/FileBrowser.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/shell/android-studio/app/src/main/java/com/reicast/emulator/FileBrowser.java b/shell/android-studio/app/src/main/java/com/reicast/emulator/FileBrowser.java index 997d4bad9..1a12660b1 100644 --- a/shell/android-studio/app/src/main/java/com/reicast/emulator/FileBrowser.java +++ b/shell/android-studio/app/src/main/java/com/reicast/emulator/FileBrowser.java @@ -208,18 +208,17 @@ public class FileBrowser extends Fragment { in.close(); out.close(); } else if (!file.exists()) { - file.getParentFile().mkdirs(); - file.createNewFile(); - OutputStream fo = new FileOutputStream(file); + org.apache.commons.io.FileUtils.touch(file); InputStream png = getActivity().getAssets().open("buttons.png"); - + OutputStream fo = new FileOutputStream(file); byte[] buffer = new byte[4096]; - int len = 0; - while ((len = png.read(buffer)) != -1) { - fo.write(buffer, 0, len); + int read; + while ((read = png.read(buffer)) != -1) { + fo.write(buffer, 0, read); } - fo.close(); png.close(); + fo.flush(); + fo.close(); } } catch (FileNotFoundException fnf) { fnf.printStackTrace();