开发者

File System Listener

开发者 https://www.devze.com 2023-03-24 17:48 出处:网络
I would like to know if it is possible to have a listener in my application for notifying events when 开发者_如何学JAVAa file is added to the file system. Can someone kindly guide me with this.

I would like to know if it is possible to have a listener in my application for notifying events when 开发者_如何学JAVAa file is added to the file system. Can someone kindly guide me with this.

Thanks in advance.


You should use a FileObserver to monitor for changes to files or directories.

There seems to be an example here, but I've not tried it so can't vouch for it's correctness.


try this:

new FileObserver(path) {
    @Override
    public void onEvent(int event, String path) {
        if (event == FileObserver.CREATE)
            Toast.makeText(getActivity(), "File created", Toast.LENGTH_SHORT).show();
        }
    }.startWatching();
0

精彩评论

暂无评论...
验证码 换一张
取 消