本帖最后由 yasyas001 于 2013-6-22 22:31 编辑
//我把所有的都写入了for里面,这样的代码怎么样,.请各位指教下!- public class CopyFolderTest {
- public static void main(String[] args) throws IOException {
- // String[] strArr = new File("d:\\Java").list(new FilenameFilter() {
- //
- // @Override
- // public boolean accept(File dir, String name) {
- // return new File(dir,name).isFile() && name.endsWith(".java");
- // }
- // });
- //遍历 封装数据源 文件 过滤器
- for (String str : new File("d:\\Java").list(
- new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
-
- return new File(dir, name).isFile() && name.endsWith(".java");}}))
- { //输入流读取遍历到的合法文件,并装入一个新的文件集合中
- BufferedReader br = new BufferedReader(new FileReader(new File(
- "d:\\Java", str)));
-
- //写入新的文件夹中并改名,
- BufferedWriter bw = new BufferedWriter(new FileWriter(new File(
- new File("d:\\jad"), str.replace(".java", ".jad"))));
-
- String line = null;
- while ((line = br.readLine()) != null) {
- bw.write(line);
- bw.newLine();
- bw.newLine();
- }
- br.close();
- bw.close();
- }
- }
- }
复制代码 |