I am developing an application with a screen saver downloading several files before the files start to load. I want to check if the files already exist or not, and if they exist, I want to delete them. The code shown below contains the correct paths to the file, and the file check function seems to work, as reading in Logcat indicates "file deleted."
However, when I check the phone itself, I see that every time I launch the application, another 2 files are added to the folder with the same name, but with an increase in the number
eg. Launch 1 ... I get
clientraw.txt clientrawextra.txt
Run 2 ... I get
clientraw.txt clientrawextra.txt clientraw-1.txt clientrawextra-1.txt
etc.
Therefore, it would seem that the delete function does not work, any help would be appreciated!
//Code that checks if the clientraw.txt file already exists, if so the file is deleted File sdCard = Environment.getExternalStorageDirectory(); File file = new File(sdCard.getAbsolutePath() + "/Download", client); Log.d("file path", String.valueOf(file)); if (file.exists()) { file.delete(); Log.d("file", "file deleted"); } File sdCardextra = Environment.getExternalStorageDirectory(); File fileextra = new File(sdCardextra.getAbsolutePath() + "/Download", clientextra); if (fileextra.exists()) { fileextra.delete(); Log.d("file", "file deleted"); } ready();
Doesn't it seem to delete the file fast enough? When I get rid of the ready(); method ready(); (a method that downloads files), it deletes the files perfectly, so I think the files start loading before the previous files are deleted, really stuck on this ?!
source share