//get the file path from the configuration fileString FilePath = Global.getconfig ("FilePath", "Log-resolve.properties"); String Copyfilepath= Global.getconfig ("Copyfilepath", "Log-resolve.properties");Try{String encoding= "Utf-8"; File File=NewFile (filePath);//determine if a file existsif(File.isfile () &&file.exists ()) { //step1 backup files, clean up the original filescopyFile (FilePath, Copyfilepath); FileWriter FW=NewFileWriter (file); BufferedWriter BW=NewBufferedWriter (FW); Bw.write (""); Bw.close (); //Step2 Read the backup file and parse the storageFile fileCopy =NewFile (Copyfilepath); InputStreamReader Read=NewInputStreamReader (NewFileInputStream (fileCopy), encoding); BufferedReader BufferedReader=NewBufferedReader (read); String Linetxt= ""; while((Linetxt=bufferedreader.readline ())! =NULL) {System.out.println (linetxt); //Intercept String//Intercept File NumberString filenumber = linetxt.substring (0, Linetxt.indexof ("" ")); //Intercept start timeString str = linetxt.substring (0, Linetxt.lastindexof ("")-1); String StartTime= Str.substring (Str.lastindexof ("") +1); //intercepting file namesString fileName = str.substring (Str.indexof ("") +2, Str.lastindexof ("")-1); //Intercept End TimeString endTime = linetxt.substring (Linetxt.lastindexof ("") +1); Onewayrunlog Onewayrunlog=NewOnewayrunlog (); Onewayrunlog.setfilenumber (filenumber); Onewayrunlog.setfilename (FileName); Onewayrunlog.setstarttime (StartTime); Onewayrunlog.setendtime (EndTime); Onewayrunlogservice.save (Onewayrunlog); } read.close ();}Else{System.out.println ("The specified file cannot be found");}/*** File backup **/ Public Static intcopyFile (String src, string dst) {Try { intLen = 0; byte[] buf =New byte[1024]; FileInputStream FIS=NewFileInputStream (SRC); FileOutputStream Fos=NewFileOutputStream (DST); while(len = Fis.read (BUF))! =-1) {fos.write (buf,0, Len); } fis.close (); Fos.close (); } Catch(IOException e) {System.out.println (e); return-1; } return0; }
Java reads local file backup and resolves inbound