- package practise;
- import java.io.*;
- public class test_02 {
- public static void main(String[] args) throws Exception {
- move();
- }
- public static void move() throws Exception
- {
- File file=new File("/home/wtmz/workspace/a/");
- File[] files=file.listFiles(new FileFilter()
- {
- public boolean accept(File f)
- {
- return f.getName().endsWith(".java");
- }
-
- });
-
- for(File f:files)
- {
- // System.out.println(f);
- copyTo(f,"/home/wtmz/workspace/b/");
- }
-
- }
- public static void copyTo(File f,String dst) throws Exception
- {
- BufferedReader bufr=new BufferedReader (new FileReader(f));
- BufferedWriter bufw=new BufferedWriter(new FileWriter(dst+f.getName()));
-
- char[] buf=new char[1024];
- int len=0;
- while((len=bufr.read(buf))!=-1)
- {
- bufw.write(buf,0,len);
- }
- bufw.close();
- bufr.close();
- }
- }
复制代码
这是自己电脑上运行的( kubuntu系统下),:lol 做出来发现和楼上用字节流的没啥差啊:L |