zoukankan      html  css  js  c++  java
  • i/o流(2)

    public class TestCopyArray {
      public static void main(String[] args) throws Exception {
        InputStream is = new FileInputStream("第10章/a.txt");
        OutputStream os = new FileOutputStream("第10章/b.txt");
        byte[] bs = new byte[1024];
        while(true){
          int length = is.read(bs);
          //从下标0开始,把length长度写到文件中
          os.write(bs,0,length);
          if(length<1024){
            break;
        }
      }
      is.close();
      os.close();
      }
    }

    注意:a.boolean:表示是否向文件末尾追加,如果是true表示追加,false表示不追加(也就是覆盖),默认值是false;

       b.创建FileOutputStream实例时,如果相应的文件并不存在,则会自动创建一个空的文件。

  • 相关阅读:
    Linux下制作和使用静态库和动态库
    C语言的内存管理
    C语言柔性数组
    大小端模式
    C位域操作
    C/C++字节对齐
    C/C++指针
    Linux之Socket编程
    VSCode配置FTP
    GCC的编译过程和链接
  • 原文地址:https://www.cnblogs.com/wojiatingting/p/6824175.html
Copyright © 2011-2022 走看看