Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我已经从活动创建了一个存储在内部存储中的文件。如何从另一个活动中删除此文件?
我想我必须获取文件的目录(我不确定如何)并删除它。我尝试使用
context.deleteFile();
但它不起作用,因为我试图从非静态方法调用它。
这是你的答案:
File dir = getFilesDir(); File file = new File(dir, "my_filename"); boolean deleted = file.delete();
您可以尝试让实例指向文件并将其删除,就像在 这个答案 或这个