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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© threeforPP 中级黑马   /  2015-7-3 22:08  /  287 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

package cn.itcast;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/*
* 复制单级文件夹内容
*/
public class Test2 {

        public static void main(String[] args) throws IOException {
                //新旧文件夹路径
                File srcDIR = new File("src/cn/itcast");
                File destDIR = new File("HAHAHA");
                //获取原文件夹下的所有文件对象
                File[] file = srcDIR.listFiles();
                //遍历数组,依次拿到每一个File对象
                for (File oldFile : file) {
                        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(oldFile));
                        //????
                        String fileName = oldFile.getName();
                        //???
                        File newFile = new File(destDIR,fileName);
                       
                        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newFile));
                        //读
                        byte[] bytes = new byte[1024];
                        int len;
                        while((len=bis.read(bytes))!=-1){
                                //写
                                bos.write(bytes, 0, len);
                        }
                        bos.close();
                        bis.close();
                }
        }
}
请问大神上面的
//????
String fileName = oldFile.getName();
//???
File newFile = new File(destDIR,fileName);
这两个注释应该写什么啊,程序会写,但是不知道这两句的具体意思,想记得更牢固些,求大神指点!
谢谢

0 个回复

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