• Java复制文件


    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    
    public class Test {
    
            public static void main(String[] args) throws IOException {
    
                    File srcForder = new File("d:\");
    
                    File destForder = new File("d:\Test\");
    
                    isFile(srcForder, destForder);
            }
    
            private static void isFile(File srcForder, File destForder) throws IOException {
    
                    if (!destForder.exists())
    
                            destForder.mkdir();
    
                    File[] file = srcForder.listFiles();
    
                    if (file != null) {
    
                            for (File srcFile : file) {
    
                                    if (srcFile.isDirectory()) {
    
                                            isFile(srcFile, destForder);
    
                                    } else {
    
                                            if (srcFile.getName().endsWith(".java")) {
                                                    
                                                    File destFile = new File (destForder,srcFile.getName()) ;
    
                                                    copyFile(srcFile, destFile);
                                            }
                                    }
                            }
                    }
            }
    
            private static void copyFile(File srcFile, File destFile) throws IOException {
    
                    BufferedReader br = new BufferedReader(new FileReader(srcFile));
    
                    BufferedWriter bw = new BufferedWriter(new FileWriter(destFile)) ;
    
                    String line = null ;
                    while ((line = br.readLine()) != null) {
    
                            bw.write(line);
                            bw.newLine();
                            bw.flush();
                    }
    
                    br.close();
                    bw.close();
            }
    }
    

  • 相关阅读:
    02 make和目录结构
    05 UCI
    IE6下position:fixed不固定的解决办法
    php内存溢出
    MySQL计划任务(事件调度器)(Event Scheduler)
    PHP面向对象
    php学习笔记——12年2月16日开始不断更新
    Phpnow下配置Xdebug调试
    边学边用
    ASP时间格式化函数
  • 原文地址:https://www.cnblogs.com/dengshiwei/p/4258495.html
Copyright © 2020-2023  润新知