首页 > 其他 > 详细

write写入

时间:2020-07-08 19:18:38      阅读:59      评论:0      收藏:0      [点我收藏+]

package com.itheima.Demo05Writer;

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 {
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();
}

}

write写入

原文:https://www.cnblogs.com/hk18181358129/p/13268095.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!