package example; import java.io.*; public class Test { public static void main(String[] args) throws IOException { File file1=new File ("F:"+File.separator+"src"); copyAndRename(file1); } private static void copyAndRename(File file1) throws IOException { File[] fi=file1.listFiles(new SuffixFilter()); String filename="F:"+File.separator+"src2"; byte[] buf=new byte[1024]; int len; for(File f:fi){ String fname=f.getName(); BufferedInputStream bis=new BufferedInputStream(new FileInputStream(f)); BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(filename+File.separator+fname)); while((len=bis.read(buf))!=-1){ bos.write(buf,0,len); } bis.close(); bos.close(); File f2=new File(f.getAbsolutePath()); fname=fname.replace(".java", ".txt"); File f3=new File("F:"+File.separator+"src"+File.separator+fname); f2.renameTo(f3); } } } class SuffixFilter implements FilenameFilter{ public boolean accept(File dir, String name) { return name.endsWith(".java"); } }
来不及注释了,睡觉,困死了