是否可以覆盖android中的file.delete() [英] Is it possible to override file.delete() in android

查看:308
本文介绍了是否可以覆盖android中的file.delete()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个像垃圾箱这样的回收站应用程序。当我要从任何文件管理器(Astro文件管理器,ES文件浏览器)删除任何文件时,我使用fileobserver获取已删除文件的文件路径。但是fileobserver在操作完成后返回(删除,修改等操作)。是否可以在删除文件之前获取文件路径?或者覆盖delete()?

I am doing a recyclebin app like dumpster. When i am going to delete any file from any file manager (Astro file manager, ES file explorer) , i am getting the file path of the deleted file using fileobserver. But fileobserver is returning after completion of the operation (operation like delete, modify etc..). Is it possible to get the file path before deleting the file ? or to override the delete() ?

推荐答案

我认为在删除它之前不可能获取文件路径。考虑后面的逻辑,你想要删除文件,因此FileObserver不允许您通知,直到您删除它,并且您在删除之前没有得到该路径。



但我认为它可能是完成了一些简单的事情。我不熟悉FileObserver,所以我不会谈论它。我假设你有要删除的文件列表,或者它可能是一个像文件管理器一样的列表。 />
因此,当您单击该列表视图的特定文件项时,您可以从后面的代码中获取该文件的路径:

I don't think it is possible to get the file path before deleting it.Consider the logic behind,you want to delete a file,so FileObserver don't let you notify until you delete it and also you don't get that path before deleting.

But i think it could be done implementing some simple things.I don't familiar with FileObserver,so i don't talk about that.I assume,you have the list of files that you want to delete or it may be a list works like File Manager.
So when you click on specific file item of that listview you can get the path of that file from code behind by:
File file = new File("fileName.txt");
String filePath = file.getAbsolutePath();



然后你可以提示确认对话框询问用户是否要删除该文件?如果用户选择删除,则可以通过以下方式执行:


You can then prompt a confirmation dialog asking user he want to delete that file or not?If user choose delete then you can do it by:

File file = new File(selectedFilePath);
boolean deleted = file.delete();



但是看,在删除之前你有它的文件路径,不是吗?


But look, before deleting you have the file path of it, isn't it?


这篇关于是否可以覆盖android中的file.delete()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆