search

Home  >  Q&A  >  body text

android下file.delete无法删除文件。

    File file = new File("/data/data/com.wlanplus.chang/lib/libcutil.so");
    file.delete();

执行后查看文件依然在。 后来加入如下代码

upgradeRootPermission(getPackageCodePath());//请求ROOT权限
file.setExecutable(true, false);
file.setReadable(true, false);
file.setWritable(true, false);

添加了权限:

<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

依然不行。

file.exists() file.canWrite()返回也都是true。
该怎么才能删除呢?

伊谢尔伦伊谢尔伦2842 days ago786

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 11:58:43

    Looking at the file path, it should be a problem with the file you want to delete. The system doesn’t want you to delete it, so it creates a new one every time you delete it. You can try manually deleting the file on your phone. If you still can't delete it, that's why.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 11:58:43

    /data/data/+Package name If the files in the directory are non-root, only the package name program can perform read and write operations.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 11:58:43

    You can refer to http://www.cnblogs.com/tgyf/p/4649319.html

    reply
    0
  • Cancelreply