代码之家  ›  专栏  ›  技术社区  ›  cjnash Vikey

使用文件删除文件。delete()和Uri

  •  0
  • cjnash Vikey  · 技术社区  · 9 年前

    final File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + '/' + "howmany.txt");
    
        Uri uri = Uri.fromFile(file);
        Boolean k = new File(uri.getPath()).delete();
        if(k){
            Toast.makeText(getApplicationContext(), "DELETED", Toast.LENGTH_SHORT).show();
        }
    

    我在检查了权限后立即编写了这段代码,据我所知, .delete()

    1 回复  |  直到 9 年前
        1
  •  1
  •   Rabbit Guy    9 年前

    k

    final File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + '/' + "howmany.txt");
    if (file.delete()) 
        Toast.makeText(getApplicationContext(), "DELETED", Toast.LENGTH_SHORT).show();