import java.io.*;
class CopyJava
{
public static void main(String[] args)
{
File orig=new File("d:\\java\\day18");
File dest=new File("d:\\test\\");
if(!dest.exists())
dest.mkdirs();
if(!dest.isDirectory())
dest.mkdir();
File[] files=orig.listFiles();
for(File file:files)
{
if(file.isFile()&&file.getName().endsWith(".java"))
{
System.out.println(file+"...."+dest);
copy(file,dest);
}
}
}
public static void copy(File file,File dest)
{
FileReader fr=null;
FileWriter fw=null;
try
{
fr=new FileReader(file);
fw=new FileWriter(dest+"\\"+file.getName());
System.out.println(file+"...."+dest+">>>"+file.getName());
char[] buf=new char[1024];
int num=0;
while((num=fr.read(buf))!=-1)
fw.write(buf,0,num);
}
catch (IOException e)
{
System.out.println(e.toString());
}
finally
{
if(fw!=null)
try
{
fw.close();
}
catch (IOException e)
{
System.out.println(e.toString());
}
if(fr!=null)
try
{
fr.close();
}
catch (IOException e)
{
System.out.println(e.toString());
}
}
}
}
|
|