zoukankan      html  css  js  c++  java
  • BufferedInputStream&BufferedOutputStream

    使用字符缓冲区相关实现copy文件;

    public static void main(String[] args) {
            //创建文件对象指定要拷贝的文件路径(源文件),文件须存在,测试用例不做判断
            File srcFile=new File("E:\CloudMusic\mp3\a.mp3");
            //创建文件对象指定文件拷贝的目标路径
            File destFile=new File("d:\test1.mp3");
            System.out.println("正在复制文件.......");
            try {
                //创建文件输入流对象
                FileInputStream fin=new FileInputStream(srcFile);
                //创建缓冲区输入流对象(加快文件的读取效率)
                BufferedInputStream bin=new BufferedInputStream(fin);
                
                
                
                //创建文件输出流对象
                FileOutputStream fout=new FileOutputStream(destFile);
                //创建缓冲区输出流对象,加快文件流的输出效率
                BufferedOutputStream bout=new BufferedOutputStream(fout);
                
                
                //声明int类型的变量准备逐字节拷贝文件
                int b;
                while((b=bin.read())!=-1){
                    bout.write(b);//写出字节到文件
                }
                
                bout.flush();
                bout.close();
                bin.close();
                System.out.println("文件拷贝结束!");
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
  • 相关阅读:
    接口和类的关系
    Java9+版本中,Interface的内容
    XSS简介
    上传漏洞(一)
    上传漏洞(二)
    初学Django
    ISCC:Please give me username and password!
    各种密码
    Debian 8.9 搭建wordpress个人博客
    网安相关书籍
  • 原文地址:https://www.cnblogs.com/xh_Blog/p/6591196.html
Copyright © 2011-2022 走看看