In the Android application I'm working on, the user should be able to create a new CSV file on the SD card, named using the text that they enter into the EditText.
The problem is that after creating the file instance using the directory and file name, file.exists () returns false , even if the file really exists in this place. I was browsing the SD card using the Android file browser and through Windows Explorer, and the file exists.
Is it right to check if the file exists, and if so, what am I missing for it to return true when it exists?
String csvname = edittext.getText().toString() + ".csv"; File sdCard = Environment.getExternalStorageDirectory(); //path returns "/mnt/sdcard" File dir = new File (sdCard.getAbsolutePath() + "/Android/data/" + getPackageName() + "/files/"); // path returns "/mnt/sdcard/Android/data/com.phx.license/files" dir.mkdirs(); File file = new File(dir, csvname); //path returns "/mnt/sdcard/Android/data/com.phx.license/files/Test.csv" if(!file.exists()) //WHY DOES IT SAY IT DOESN'T EXIST WHEN IT DOES? { ... }
java android file file-io
Gady
source share