At com. Cdly. Test. FileListener. OnFileCreate (55) FileListener. Java:
At org.apache.com mons. IO. Monitor. FileAlterationObserver. DoCreate (FileAlterationObserver. Java: 379)
At org.apache.com mons. IO. Monitor. FileAlterationObserver. CheckAndNotify (FileAlterationObserver. Java: 330)
At org.apache.com mons. IO. Monitor. FileAlterationObserver. CheckAndNotify (FileAlterationObserver. Java: 304)
At org.apache.com mons. IO. Monitor. FileAlterationMonitor. Run (182) FileAlterationMonitor. Java:
at java.lang.Thread.run(Unknown Source)
CodePudding user response:
Talk is being, show me the codeCodePudding user response:
No code?CodePudding user response:
Public class Test {Public static void main (String [] args) throws the Exception {
//monitor directory
String rootDir="D: \ \ baidu";
//polling interval 5 seconds
The Integer time=3;
Long interval=TimeUnit. SECONDS. ToMillis (time);
//to create a file is used to handle file format,
//FileFilterUtils. SuffixFileFilter (". TXT ")
FileAlterationObserver _observer=new FileAlterationObserver (
RootDir,
FileFilterUtils. And (
FileFilterUtils. FileFileFilter ()),//filter file format
Null);
FileAlterationObserver observer=new FileAlterationObserver (rootDir);
The observer. AddListener (new FileListener ());//Settings file change listener
//create a file change listener
FileAlterationMonitor monitor=new FileAlterationMonitor (interval, the observer).
//start monitoring
Try {
The monitor. The start ();
} the catch (Exception e) {
e.printStackTrace();
}
}
}
CodePudding user response:
Public class FileListener extends FileAlterationListenerAdaptor {Private DbosService dboService;
Public void onFileCreate (File File) {
The String fileName=file. The getName ();
String [] str1=fileName. The split (" _ ");
StringBuffer sb=new StringBuffer ();
String serialNum="";
String dnOrUp="";
String communTime="";
String imsi="";
String imei="";
String tmsi="";
String fileLen=String. The valueOf (file. The length ());
String filePath=file. GetPath ();
for(int i=0; i
}
Sb. DeleteCharAt (sb. Length () - 1);
String str3=sb. ToString ();
String str2 []=str3. Split (" ");
for(int j=0; j
DnOrUp=str2 [1];
CommunTime=str2 [2];
Imsi=str2 [3];
Imei=str2 [4];
Tmsi=str2 [5];
}
Dbos Dbos=new Dbos ();
Dbos. SetSerialNum (serialNum);
Dbos. SetDnOrUp (dnOrUp);
Dbos. SetCommunTime (communTime);
Dbos. SetImsi (imsi);
Dbos. SetImei (imei);
Dbos. SetTmsi (tmsi);
Dbos. SetFileLen (fileLen);
Dbos. SetFilePath (filePath);
System. The out. Println (dbos getSerialNum ());
DboService. AddDbos (dbos);
}
These are the main two class code
CodePudding user response:
See this FileListener near line 55, post code, so you couldn't see what is 55CodePudding user response:
Positioning in: ats com cdly. Test. FileListener. OnFileCreate (55) FileListener. Java:See you at FileListener. Java line55
But I thought you didn't 55 it stick out like line,,,
CodePudding user response:
55 line is dboService. AddDbos (dbos);CodePudding user response: