package test;
import java.io.File;
import java.io.FileFilter;
public class MyFilter implements FileFilter {
@Override
public boolean accept(File file) {
if(file.isDirectory())
return true;
else
{
String name = file.getName();
if(name.endsWith(".txt") || name.endsWith(".mp4"))
return true;
else
return false;
}
}
}
package test;
import java.io.*;
public class test3 {
public static void main(String[] args) throws IOException {
File f=new File("e:\\test");
MyFilter m=new MyFilter();
File[]file= f.listFiles(m);
for(File file1:file){
String destFileName=file1.getName().replaceAll(".txt",".java");
moveto(file1,destFileName);
}
}
private static void moveto(File f,String dname) throws IOException {
int len=0;
FileInputStream in=new FileInputStream(f);
File ff= new File("E:\\test1"+"\\"+dname);
if(!ff.exists()){
ff.getParentFile().mkdir();
}
FileOutputStream outputStream=new FileOutputStream(ff);
byte[]bytes=new byte[10];
while ((len=in.read(bytes))!=-1){
outputStream.write(bytes,0,len);
}
in.close();
outputStream.close();
}
}