zoukankan      html  css  js  c++  java
  • Java基础知识强化之IO流笔记19:FileOutputStream的三个write方法

    1. FileOutputStream的三个write方法:

     void write(byte[] buffer)
              Writes the entire contents of the byte array buffer to this stream.
     void write(byte[] buffer, int offset, int count)
              Writes count bytes from the byte array buffer starting at offset to this stream.
     void write(int oneByte)
              Writes the specified byte oneByte to this stream.

    2. 代码示例:

     1 package com.himi.fileoutputstream;
     2 
     3 import java.io.FileNotFoundException;
     4 import java.io.FileOutputStream;
     5 import java.io.IOException;
     6 
     7 /**
     8  * 
     9  *字节输出流操作步骤:
    10  *        第一步:创建字节输出流对象
    11  *        第二步:写数据
    12  *        第三步:关闭字节输出流对象
    13  *
    14  *  void    write(byte[] buffer) 
    15  *         Writes the entire contents of the byte array buffer to this stream.
    16  *         
    17  *    void    write(byte[] buffer, int offset, int count) 
    18  *         Writes count bytes from the byte array buffer starting at offset to this stream.
    19  *         
    20  *  void    write(int oneByte) 
    21  *         Writes the specified byte oneByte to this stream.
    22  *
    23  *
    24  */
    25 
    26 
    27 public class FileOutputStreamDemo2 {
    28 
    29     public static void main(String[] args) throws IOException{
    30         //创建字节输出流对象
    31         FileOutputStream fos = new FileOutputStream("fos2.txt");
    32         
    33         //写数据
    34         //write(int oneByte) 97---底层二进制数据--通过记事本打开--找到97对应的字符值--a
    35         
    36         for (int i = 97; i < 110; i++) {
    37             fos.write(i);
    38         }
    39         
    40         
    41         //写数据
    42         //write(byte[] buffer)  写一个字节数组 ,对应也是字符
    43         byte[] bytes = {111,112,113,114,115};
    44         fos.write(bytes);
    45         
    46         //写数据
    47         //write(byte[] buffer, int offset, int count) 写一个字节数组的一部分
    48         fos.write(bytes, 1, 3);
    49         
    50     
    51 
    52     }
    53 
    54 }
  • 相关阅读:
    寒假了
    【MFC】浏览器中快速打开常用工具
    【转】MFC隐藏进程自身(任务管理器不可见,wSysCheck等工具可见)
    【原】DIY属于自己的鼠标侧键
    coco2dx 3.4final 使用scale9sprite
    linux挂载新硬盘
    关于c语言中的结构体使用偏移量求值问题
    Linux的网卡由eth0变成了eth1,如何修复
    oracle归档管理
    exsi上虚拟因硬盘不足无法启动
  • 原文地址:https://www.cnblogs.com/hebao0514/p/4850712.html
Copyright © 2011-2022 走看看