Start adb consol and write follwing command
adb shell su $rm /yourpath/to/yourfilename
delete your o size file.
Question
I'm working on a project that deals with files and I had difficult time trying to delete a file. Luckily, it was working and it still works for me.
The problem I had was I was trying to delete a file that is empty:
file.length()==0
So I solved my problem but I'm still left with a question.
file.length()
returns 0 in both cases
file
does not exist in the pathSo How am i supposed to eliminate the files that have 0 size in my file explorer. I have too many files with size 0 and I want to erase them from my /files/
.
Yes, I tried selecting on the file and clicking on red X several times, but I guess eclipse does not read file with 0 size. With AVD, I could make a new AVD and launch it with formatted setting, but in real life, you can't just buy a new phone to get rid of files with size 0.
Help me how to do this on ECLIPSE please
Thank you
Solution
Start adb consol and write follwing command
adb shell su $rm /yourpath/to/yourfilename
delete your o size file.
OTHER TIPS
You can distinguish between a file that does not exist and an empty file by using
if (file.exists() && file.length() == 0) {
// existing, empty file
} else {
// file does not exist or exists and is not empty
}
You might also find the methods File.isFile()
and File.isDirectory()
useful.
In your code you should first create a file object and then check if it exists before trying to delete it:
File myFile = new File(path); // path is the absolute path of the file that you want to delete
if (myFile.exists()){
// Delete
boolean deletedFile = myFile.delete();
// Check if the file was deleted
if(deletedFile){
// Delete successful
}
else{
// Error
}
}