Home > Mobile >  Data files under/data/package/files, call the file. Delete, why don't delete off
Data files under/data/package/files, call the file. Delete, why don't delete off

Time:11-26

Equipment: Pixel AS built-in simulator 2 API 25, Lenovo TB - X705M Android8.1.0
Delete calls, but returns false, does not appear any exception,
Through the chmod awarded 777 DWRX file permissions,
Absolute and relative paths are tried,
The rm command can delete files,
 public void delFiles (View v) throws IOException {
//Toast. MakeText (this, "click the delete files button", Toast. LENGTH_SHORT), show ();
//deleteExpiredFile (0, getFilesDir () + "");
String dir=getExternalFilesDir (null). GetAbsolutePath () + File. The separator + "TMPXXX";
The File d=new File (dir);
if (! D.e xists ())
D.m kdir ();
DeleteExpiredFile (0, d);
//deleteDirectory (getFilesDir (.) getAbsoluteFile ());
}

/* *
* delete more than save time log file
*

* @ param day to save time*/
Private static void deleteExpiredFile (long day, the File dir) {
Long currentTime=System. CurrentTimeMillis ();
//File dir=new File (filePath);
{if (dir. IsDirectory ())
The File files []=dir. ListFiles ();
If (files!=null & amp; & Files. The length & gt; 0 {

For (the File item: files) {
Try {
Long lastModified=item. LastModified ();
If (currentTime - lastModified & gt; Day {
Boolean isdelect=item. The delete ();//delete the directory success
If (isdelect) {
The d (" ff ", "1111");
}
}



} the catch (Exception e) {
e.printStackTrace();
}
}
}
}
}

Public void deleteDirectory (File File) throws IOException {
If (the file. The exists ()) {
If (the file. The isDirectory ()) {
The File files []=File. ListFiles ();
for(int i=0; iIf (files [I] isDirectory ()) {
DeleteDirectory (files [I]);
}
The else {
if (! Files [I] the delete ()) {
Throw new IOException (" failed to the file ");
} else {
The d (" aa ", "delete success");
}
}
}
}
//file. The delete ();
}
}

CodePudding user response:

The shell implementation class can you send me see

CodePudding user response:

The shell implementation class can you send me see