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:
parent
f88cb7f0e4
commit
60b501b747
|
@ -208,18 +208,17 @@ public class FileBrowser extends Fragment {
|
||||||
in.close();
|
in.close();
|
||||||
out.close();
|
out.close();
|
||||||
} else if (!file.exists()) {
|
} else if (!file.exists()) {
|
||||||
file.getParentFile().mkdirs();
|
org.apache.commons.io.FileUtils.touch(file);
|
||||||
file.createNewFile();
|
|
||||||
OutputStream fo = new FileOutputStream(file);
|
|
||||||
InputStream png = getActivity().getAssets().open("buttons.png");
|
InputStream png = getActivity().getAssets().open("buttons.png");
|
||||||
|
OutputStream fo = new FileOutputStream(file);
|
||||||
byte[] buffer = new byte[4096];
|
byte[] buffer = new byte[4096];
|
||||||
int len = 0;
|
int read;
|
||||||
while ((len = png.read(buffer)) != -1) {
|
while ((read = png.read(buffer)) != -1) {
|
||||||
fo.write(buffer, 0, len);
|
fo.write(buffer, 0, read);
|
||||||
}
|
}
|
||||||
fo.close();
|
|
||||||
png.close();
|
png.close();
|
||||||
|
fo.flush();
|
||||||
|
fo.close();
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException fnf) {
|
} catch (FileNotFoundException fnf) {
|
||||||
fnf.printStackTrace();
|
fnf.printStackTrace();
|
||||||
|
|
Loading…
Reference in New Issue