RT,可以提供代码或者工具!
解决方案 »
- thickbox 在本页面 传id疑问
- Java Web客户端怎么通过Socket和MFC服务器通信
- struts-config.xml 必须放在 WEB-INF下吗,放在src目录下怎么读取
- 关于spring管理事务的问题 请高人解答 谢谢
- 求教关于jsp连接dbf数据库的问题
- Tomcat5.0.28+JDK1.5.0_06+MySQL+Lomboz问题,请大家帮忙啊
- cms-core:jar:0.0.1-SNAPSHOT is missing, no dependency information available错误
- 问一下下面这个action标签几个属性的用法
- 求weblogic+jbuilder9+oracle9的开发实例(使用EJB)
- sax2大数据优化方案,分不够在加
- SSH项目启动报错
- 关于start调用问题
/**
*@项目名称: ${project_name}
*@文件名称: ${file_name}
*@Date: ${date}
*@Copyright: ${year} www.xxx.com Inc. All rights reserved.
*注意:本内容仅限于xxx公司内部传阅,禁止外泄以及用于其他的商业目的
*/
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");
}}