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.
This commit is contained in:
TwistedUmbrella 2018-03-31 16:26:17 -04:00
parent f88cb7f0e4
commit 60b501b747
1 changed files with 7 additions and 8 deletions

View File

@ -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();