时 间 记 忆
<<  < 2013 - >  >>
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
 
最 新 日 志
 
最 新 评 论
 
最 新 留 言
 
搜 索
 
用 户 登 录
 
友 情 连 接
 


 
 
将d:\java目录下的所有.java文件复制到d:\jad目录下,并将原来文件的扩展名从.java
[ 2013-6-1 18:59:00 | By: Patience ]
 
public class CopyFolderTest2 {
public static void main(String[] args) throws IOException {
// 封装目录
File file = new File("d:\\java");
File file2 = new File("d:\\jad");

// 获取满足条件的文件名称
String[] strArray = file.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return new File(dir, name).isFile() && name.endsWith(".java");
}
});

// 遍历
for (String str : strArray) {
// 数据源
File src = new File(file, str);

// 修改后的文件
String newName = str.replace(".java", ".jad");
File dest = new File(file2, newName);

// 复制文件
// File file =new File("c:\\a.txt");
// c:\\a.txt 效果一样
BufferedReader br = new BufferedReader(new FileReader(src));
BufferedWriter bw = new BufferedWriter(new FileWriter(dest));

// 读写数据
String line= null;
while((line=br.readLine())!=null){
bw.write(line);
bw.newLine();
bw.flush();
}
bw.close();
br.close();

}
}
}
 
 
  • 标签:it 
    发表评论:
     
    天涯博客欢迎您!