码迷,mamicode.com
首页 > Web开发 > 详细

递归遍历文件中所有html文件保存

时间:2020-04-30 15:40:34      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:保存   lis   tput   read   with   sub   ati   use   遍历文件   

import java.io.*;

public class Test {
    public static void main(String[] args) throws IOException {
        File file = new File("/Users/mima000000/Desktop/health/讲义");
        te(file);


    }

    public static void te(File file) throws IOException {
        File[] files = file.listFiles();
        for (File file1 : files) {
            if (file1.isFile()){
                if (file1.toString().endsWith(".html")){
                    String name = file1.getName();
                    String resname = name.substring(0, name.lastIndexOf("."));
                    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file1));
                    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File("/Users/mima000000/Desktop/health/res/"+resname+".html")));
                    int len;
                    byte[] content = new byte[1024*10];
                    while ((len = (bis.read(content)))!= -1){
                        bos.write(content,0,len);
                    }

                }
            }else {
                te(file1);
            }
        }
    }
}

递归遍历文件中所有html文件保存

标签:保存   lis   tput   read   with   sub   ati   use   遍历文件   

原文地址:https://www.cnblogs.com/hellosiyu/p/12808889.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!