Java generates TXT log files

Source: Internet
Author: User
Tags system log

1 /**2 * Generate log files (files are located under Tomcat's installation path)3 * @paramStr4 */5  Public Static voidlogfortxt (String str) {6     Try {7String dir = system.getproperty ("User.dir") + file.separator + "System log";8File fi =NewFile (dir);9       if(!fi.exists ()) {Ten fi.mkdirs (); One } ADate Date =NewDate (); -String time =NewSimpleDateFormat ("Yyyy-mm-dd"). Format (date); -dir = Fi.getpath () + File.separator + time + ". txt"; thefi =NewFile (dir); -       if(!fi.exists () &&!fi.isdirectory ()) { - fi.createnewfile (); -PrintWriter PW =NewPrintWriter (NewBufferedWriter (NewFileWriter (FI))); +Pw.println ("" +NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (date) + "Generate log File"); -PW.PRINTLN ("-----------------------------Log-----------------------------"); + pw.println (str); A pw.close (); at}Else { -PrintWriter PW =NewPrintWriter (NewBufferedWriter (NewFileWriter (FI,true))); - pw.println (str); - pw.close (); - } -}Catch(Exception e) { in e.printstacktrace (); - } to}

Java generates TXT log files

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: 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.