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 }
  • 相关阅读:
    遍历及线索化二叉树
    二叉树
    程序的内存布局
    C语言一些易混淆的概念
    C语言标准库函数memcpy和memmove的区别以及内存重叠问题处理
    柔性数组
    一个基于QT简单登录对话框(带验证码功能)
    Qt中的布局管理器
    Qt中的标准对话框
    一个基于QT简单登录对话框
  • 原文地址:https://www.cnblogs.com/hebao0514/p/4850712.html
Copyright © 2011-2022 走看看