Java Tools class: Add copyright information to Programs

Source: Internet
Author: User
Tags string back

Our nine-day bird-to-peer network loan system is basically a development completed.
Now, you want to add the copyright information to the backend Java code.
Manual go to Copy-paste, too no technical content.

So, wrote a Java tool class, to add copyright information to the Java source file.
The source code, the beginning of the comment, is the copyright description. Detailed implementation, just look at the code bar.

 /* *copyright©2015 Jiutianniao * Wuhan nine days Bird Technology Co., Ltd. *http://jiutianniao.com *all rights reserved. */package Com.jiutianniao.p2p.base.util;import Java.io.bufferedreader;import Java.io.file;import Java.io.filereader;import java.io.filewriter;import org.apache.log4j.logger;//to Java file, add copyright information public class Copyrightutil {private static Logger log = Logger.getlogger (copyrightutil.class);p ublic static void Main (string[] args) t Hrows Exception {//java file is in the same directory as String dir = "E:/gitrepository/funds"; File File = new file (dir); addcopyright4directory (file);} public static void Addcopyright4directory (file file) throws Exception {file[] files = file.listfiles (); if (files = = NULL | | Files.length = = 0) {return;} for (File f:files) {if (F.isfile ()) {addcopyright4file (f); System.out.println ("file = = =" + F.getname ());} else {System.out.println ("directory = =" + F.getname ()); Addcopyright4directory (f);}} public static void Addcopyright4file (file file) throws Exception {String fileName = File.getname (); Boolean Isjava = Filena Me.endswITH (". Java"), if (!isjava) {log.info ("This file was not Java source file,filaname=" + fileName); if (Isjava) {//String copyright = "/*\n *copyright©2015 jiutianniao\n" + "* Wuhan nine Days Bird Technology Co., LTD. \ n" + "*http://jiutianniao.            Com\n "+" *all rights reserved.\n */\n "; Trying to use the RANDOMACCESSFILE.WRITEUTF, the problem is that the opening character is "NUL", not resolved. BufferedReader br = new BufferedReader (new FileReader (file)); String Line; String content = "";//Read a line, be sure to add "line break", Windows can directly use "\ n" String lineseperator = "\ n";//lineseperator = System.getproperty ("Line.separator") while (line = Br.readline ())! = null) {content + + line + lineseperator;}        Br.close (); Write the stitched string back fileWriter FileWriter = new FileWriter (file); Filewriter.write (copyright); filewriter.write (content); Filewriter.close ();}}}

Wuhan nine days bird-p2p network Loan system development-Internet application software developmentCompany official website: http://jiutianniao.com Social quiz: http://ask.jiutianniao.com

Java Tools class: Add copyright information to Programs

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.