RT,可以提供代码或者工具!

解决方案 »

  1.   

    设置一下模板。//设置注释模板的入口: Window->Preference->Java->Code Style->Code Template 然后展开Comments节点就是所有需设置注释的元素啦。
     
     
    /**
    *@项目名称: ${project_name}
     
    *@文件名称: ${file_name}
      *@Date: ${date}
    *@Copyright: ${year} www.xxx.com Inc. All rights reserved.
     
    *注意:本内容仅限于xxx公司内部传阅,禁止外泄以及用于其他的商业目的
    */
      

  2.   

    我的代码已经存在,希望补上公司标识。 上面回答的是新建java类时自动生成的内容想了想,就用代码实现了,读出所有java文件,将公司标识加入到文件最后 。import java.io.FileNotFoundException;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.File;
    import java.io.PrintWriter;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;public class copyrightAllFiles {
            public copyrightAllFiles() {
            }
            /**
             * 获取文件夹下所有java文件并写入公司信息
             */
            public static boolean readfile(String filepath) throws FileNotFoundException, IOException {
                    try {                        File file = new File(filepath);
                            if (!file.isDirectory()) {
                                    System.out.println("文件:");
                                    System.out.println("path=" + file.getPath());
                                    System.out.println("absolutepath=" + file.getAbsolutePath());
                                    System.out.println("name=" + file.getName());
                                    long lastcount = file.lastModified();
                                    String lastdate = long2StringDate(lastcount);
                                    if(checkIsJavaFiles(file.getName()))
                                    {
                                     //写入信息
                                     String content = getCorperationInfo(lastdate,file.getName());
                                     writeLogs(file.getAbsolutePath(),content);
                                    }                        } else if (file.isDirectory()) {
                                    System.out.println("文件夹:");
                                    String[] filelist = file.list();
                                    for (int i = 0; i < filelist.length; i++) {
                                            File readfile = new File(filepath + "\\" + filelist[i]);
                                            if (!readfile.isDirectory()) {
                                                    System.out.println("path=" + readfile.getPath());
                                                    System.out.println("absolutepath="
                                                                    + readfile.getAbsolutePath());
                                                    System.out.println("name=" + readfile.getName());
                                                    long lastcount = readfile.lastModified();
                                                    String lastdate = long2StringDate(lastcount);
                                                    if(checkIsJavaFiles(readfile.getName()))
                                                    {
                                                     //写入信息
                                                     String content = getCorperationInfo(lastdate,readfile.getName());
                                                     writeLogs(readfile.getAbsolutePath(),content);
                                                    }                                        } else if (readfile.isDirectory()) {
                                                    readfile(filepath + "\\" + filelist[i]);
                                            }
                                    }                        }                } catch (FileNotFoundException e) {
                            System.out.println("readfile()   Exception:" + e.getMessage());
                    }
                    return true;
            } /**
    *日志写入
    **/
            public static void writeLogs(String myFilePath,String fileContent)
            {
             FileWriter resultFile = null;
    try {
    resultFile = new FileWriter(myFilePath,true);
    } catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }
    PrintWriter myFile = new PrintWriter(resultFile);
    String strContent = fileContent;

    myFile.println(strContent);
    try {
    resultFile.close();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
            }
            /**
    *获取公司信息
    **/
            public static String getCorperationInfo(String lastdate,String filename)
            {
             byte[] c = new byte[2];
         c[0] = 0x0d;
         c[1] = 0x0a;
         String c_string = new String(c);
         StringBuilder sb = new StringBuilder();
         sb.append(c_string);
         sb.append("/**"+c_string);
         sb.append("*@公司名称: XXX"+c_string);
         sb.append("*@文件名称: "+filename+c_string);
         sb.append("*@Date: "+lastdate+c_string);
         sb.append("*@Copyright: 2011-2013 http://www.XXX.com/ Inc. All rights reserved."+c_string);
         sb.append("**/"+c_string);
             return sb.toString();
            }
            /**
    *检查是否是java类文件
    **/
            public static boolean checkIsJavaFiles(String filename)
            {
             System.out.println(filename);
             if(null!=filename)
             {
             String type = filename.substring(filename.lastIndexOf(".")+1, filename.length());
             System.out.println("filetype:"+type);
             if("java".equals(type))
             {
             return true;
             }
             }
             return false;
            }
    /**
    *long型转换为时间字符串
    **/
            public static String long2StringDate(long Time) {
         try {
        
         Date date = new Date(Time);
         DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         return format.format(date);
         } catch (Exception exp) {
         System.out.println("date convert error:" + exp);
         return "";
         }
         }
            
            public static void main(String[] args) {
                  
             try {
                            readfile("D:/logs/portal");
                            // deletefile("D:/file");
                    } catch (FileNotFoundException ex) {
                    } catch (IOException ex) {
                    }
                    System.out.println("ok");
                    
            
            }}