IO字符流6字符輸出流寫數據的其餘方法

package com.itheima.Demo05Writer;java

import java.io.FileWriter;
import java.io.IOException;程序員

/*數組

字符輸出流寫數據的其餘方法
    - void write(char[] cbuf)寫入字符數組。
    - abstract  void write(char[] cbuf, int off, int len)寫入字符數組的某一部分,off數組的開始索引,len寫的字符個數。
    - void write(String str)寫入字符串。
    - void write(String str, int off, int len) 寫入字符串的某一部分,off字符串的開始索引,len寫的字符個數。

*/
public class Demo03Writer {code

public static void main(String[] args) throws IOException {
    FileWriter fw = new FileWriter("09_IOAndProperties\\f.txt");
    char[] cs = {'a','b','c','d','e'};
    //void write(char[] cbuf)寫入字符數組。
    fw.write(cs);//abcde

    //void write(char[] cbuf, int off, int len)寫入字符數組的某一部分,off數組的開始索引,len寫的字符個數。
    fw.write(cs,1,3);//bcd

    //void write(String str)寫入字符串。
    fw.write("傳智播客");//傳智播客

    //void write(String str, int off, int len) 寫入字符串的某一部分,off字符串的開始索引,len寫的字符個數。
    fw.write("黑馬程序員",2,3);//程序員

    fw.close();
}

}索引

相關文章
相關標籤/搜索