Java reads local file backup and resolves inbound

Source: Internet
Author: User

//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

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.