A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 最初的バ梦想 中级黑马   /  2015-4-15 21:00  /  319 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

刚写了一个关于复制单级文件夹内容的代码,然后需求用UTF-8的数据类型完成,有没有大神指导怎么将GBK改为UIT-8的数据操作啊:Q
public class Test3 {

        public static void main(String[] args) throws IOException {

                File srcDir = new File("src");
                File destDir = new File("abc");
               
                method(srcDir,destDir);
        }

        public static void method(File src,File dest) throws IOException{
                File[] list = src.listFiles();
                for (File fileorDir : list) {
                        if(fileorDir.isDirectory()) {
                                File oldDir = fileorDir;
                                File newDir = new File(dest,oldDir.getName());
                                newDir.mkdir();
                                method(oldDir,newDir);
                               
                        } else {
                                File oldFile = fileorDir;
                                File newFile = new File(dest,oldFile.getName());       
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream(oldFile));
                BufferedOutputStream bos = new BufferedOutputStream(newFileOutputStream(newFile));
                                byte[] bytes = new byte[1024];
                                int len;
                                while((len=bis.read(bytes))!=-1) {
                                        bos.write(bytes, 0, len);
                                }
                                bos.close();
                                bis.close();
                        }
                }
        }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马