package findName;
import java.io.*;
import java.util.Properties;
public class FileDemo3{
public static String houZhuiName=new Source().getHouzhuiName();
public static String destPathName=new Source().getsdestPathName();
public static void main(String [] args) throws Exception{
long time1 = System.currentTimeMillis();
InputStream ips=FileDemo3.class.getResourceAsStream("config.properties");
Properties prop=new Properties();
prop.load(ips);
String sourceName=prop.getProperty("soureceName");
System.out.println(sourceName);
ips.close();
File f=new File(sourceName);
showFile(f);
long time2 = System.currentTimeMillis();
System.out.println(time2-time1);
}
public static void showFile(File dir) throws Exception{
File [] files=dir.listFiles();
for(File file:files){
if(file.isDirectory()){
showFile(file);
}
else if(file.getName().endsWith(houZhuiName)){
InputStream is=new FileInputStream(file);
BufferedInputStream buffIn=new BufferedInputStream(is);
OutputStream os=new FileOutputStream(destPathName+file.getName());
BufferedOutputStream buffOut =new BufferedOutputStream(os);
byte [] buf=new byte[1024];
int len=0;
while((len=buffIn.read(buf))!=-1){
buffOut.write(buf, 0, len);
}
}
}
}
}
class Source{
InputStream ips=FileDemo3.class.getResourceAsStream("config.properties");
Properties prop=new Properties();
public String getHouzhuiName(){
try {
prop.load(ips);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return prop.getProperty("houZhuiName");
}
public String getsdestPathName() {
try {
prop.load(ips);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return prop.getProperty("destPathName");
}
}