Android create file implementation for File Listener sample _android

Source: Internet
Author: User

Copy Code code as follows:

public class Fileobservertest extends activity{
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Myfileobserver MFO = new Myfileobserver (Getapplicationcontext (). Getfilesdir () + "/data.txt");
Mfo.startwatching ()//boot file monitoring
Mfo.stopwatching ()//Cancel file monitoring
}
public class Myfileobserver extends Fileobserver {
Public myfileobserver (String path) {
Super (path);
}

@Override
public void OnEvent (int event, String path) {
Switch (event) {
Case Android.os.FileObserver.CREATE:
File is created
LOG.D ("Fileobserver", "---file Create---");
Break
Case Android.os.FileObserver.OPEN:
File is open
LOG.D ("Fileobserver", "---File Open---");
Break
Case Android.os.FileObserver.ACCESS:
Read the file content operation after opening the file
LOG.D ("Fileobserver", "---file access---");
Break
Case Android.os.FileObserver.MODIFY:
File is modified
LOG.D ("Fileobserver", "---file MODIFY---");
Break
}

}

}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.