Java
Posted My_blog_s
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java相关的知识,希望对你有一定的参考价值。
package com.jyc.autoscanfile;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import com.atlife.callout.commons.autoRunThread.runImp.AutoRun;
import com.atlife.callout.ruleImplement.dto.domain.Cc_action_ruleimplementDto;
import com.sinosoft.sysframework.reference.DBManager;
public class AutoScanFile implements AutoRun {
private AutoScanFile autoScanFile;
private DBManager dbManager;
@Override
public String run(DBManager dbManager,
Cc_action_ruleimplementDto ccActionRuleimplementDto) {
try {
//System.out.println("running----------");
scanFile(dbManager);
//System.out.println("running-----2222-----");
return "success";
} catch (Exception e) {
// TODO 自动生成 catch 块
//e.printStackTrace();
return "failure";
}
}
//文件扫描
private void scanFile(DBManager dbManager) {
List<File> file = autoScanFile.getFiles(new File("F:\\Program Files (x86)\\test"),"MD5");
for (File ff : file) {
System.out.println(ff.getPath());
System.out.println(ff.getName());
}
}
public List<File> getFiles(File fileDir, String fileType) {
List<File> lfile = new ArrayList<File>();
File[] fs = fileDir.listFiles();
for (File f : fs) {
if (f.isFile()) {
if (fileType
.equals(f.getName().substring(
f.getName().lastIndexOf(".") + 1,
f.getName().length())))
lfile.add(f);
} else {
List<File> ftemps = getFiles(f,fileType);
lfile.addAll(ftemps);
}
}
return lfile;
}
public static void main(String[] args) {
/*AutoScanFile imp = new AutoScanFile();
DBManager dbManager = new JdbcManager();
try {
dbManager.open("platformDataSource");
imp.run(dbManager, null);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
dbManager.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}*/
}
}
以上是关于Java的主要内容,如果未能解决你的问题,请参考以下文章