java批量添加已完成代码备注

package com.gds.copyright;   
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() {   
        }   
        /**  
         * 获取文件夹下所有文件  
         */  
        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();  
        }  
          
        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;  
        }  
        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");   
                   
            
        }   
}  
代码已完成的情况下,想添加代码备注,只能往代码的最后添加。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值