import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
/*
* 字节输出流:
* public abstract void write(int b) throws IOException 一次一个字节
* public void write(byte[] b) throws IOException 一次一个字节数组
* public void write(byte[] b,int off, int len) throws IOException 一次一个字节数组的一部分
*/
public class Demo02_OutputStream {
//字节流输出的相关知识!
public static void main(String[] args) throws IOException {
//创建流对象
FileOutputStream fos = new FileOutputStream("a.txt");
//写出
byte[] bytes = new byte[]{97,98,99,100};
// fos.write(bytes);
fos.write(bytes, 0, 3);
fos.write('z');
fos.write(97);
// fos.write('一');
String s = "abcd";
byte[] bytes2 = s.getBytes();
fos.write(bytes2);
String s2 = "中";
byte[] bytes3 = s2.getBytes();
System.out.println(Arrays.toString(bytes3));
fos.write(bytes3);
//关闭流
fos.close();
}
}
|
|