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 files, add copyright information public class copyrightutil {private  Static logger log = logger.getlogger (copyrightutil.class);p ublic static void  main (String[] args)  throws exception {//java file directory 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 :&NBsp;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 = filename.endswith (". Java");if  ( !isjava)  {log.info ("This file is not java source file,filaname="  +  filename); return;} if  (Isjava)  {//  Copyright string string copyright =  "/*\n *copyright ? 2015  JiuTianNiao\n  "+ " * Wuhan nine Days Bird Technology Co., Ltd. \n  " + " *http://jiutianniao.com\n  "+ " * All rights reserved.\n */\n ";             //tried to use the Randomaccessfile.writeutf, the problem is that the opening character is "NUL", not solved. Bufferedreader br = new bufferedReader (New filereader (file)); string line; string content =  "";//Read a line, be sure to add "line break", Windows can be directly used "\ n" string lineseperator = "\ n";// Lineseperator = system.getproperty ("Line.separator") while  ((Line = br.readline ())  != null)  {content += line + lineseperator;} Br.close ();         //write the string back to the stitching 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 development

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