首页 > 学院 > 开发设计 > 正文

IO流_FileOutputStream的三个write()方法

2019-11-11 01:22:03
字体:
来源:转载
供稿:网友
package cn.itcast_01;import java.io.FileOutputStream;import java.io.IOException;/* * 字节输出流操作步骤: * 		A:创建字节输出流对象 * 		B:调用write()方法 * 		C:释放资源 *  * public void write(int b):写一个字节 * public void write(byte[] b):写一个字节数组 * public void write(byte[] b,int off,int len):写一个字节数组的一部分 */public class FileOutputStreamDemo2 {	public static void main(String[] args) throws IOException {		// 创建字节输出流对象		// OutputStream os = new FileOutputStream("fos2.txt");// 多态		FileOutputStream fos = new FileOutputStream("fos2.txt");		//调用write()方法		// public void write(int b):写一个字节		// fos.write(97);		// public void write(byte[] b):写一个字节数组		byte[] bytes = { 97, 98, 99, 100, 101 };		fos.write(bytes);		// public void write(byte[] b,int off,int len):写一个字节数组的一部分		fos.write(bytes, 1, 3);// abcdebcd		fos.close();	}}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表