Creating an instance of File does not necessarily mean that the file exists. You must write something to a file in order to create it physically.
File directory = ... File file = new File(directory, "new_file.png"); Log.d("Create File", "File exists? " + file.exists()); // false byte[] content = ... FileOutputStream out = null; try { out = new FileOutputStream(file); out.write(content); out.flush(); // will create the file physically. } catch (IOException e) { Log.w("Create File", "Failed to write into " + file.getName()); } finally { if (out != null) { try { out.close(); } catch (IOException e) { } } }
Or, if you want to create an empty file, you can simply call
file.createNewFile();
source share