java.io.OutPutStream;
/*
void write(byte[] b)将 b.length 个字节从指定 byte 数组写入此文件输出流中。 void write(byte[] b, int off, int len)将指定 byte 数组中从偏移量 off 开始的 len 个字节写入此文件输出流。 void write(int b)将指定字节写入此文件输出流。 字节输出流的使用步骤 1、创建FileOutputStream对象,构造方法中写入数据的目的地, 2、调用FileOutputStream对象中的方法Write,把数据写入到文件中, 3、释放资源
*/
private static void demo04() throws IOException { FileOutputStream fos=new FileOutputStream("IOAndProperties\\1.txt",true); fos.write(97); fos.write(65); fos.write(48); System.out.println("================================="); byte[] b={'a','f',32,33,34,'h'}; fos.write(b); fos.write(b,2,3); } /* void write(byte[] b, int off, int len)将指定 byte 数组中从偏移量 off 开始的 len 个字节写入此文件输出流。 */ private static void demo03() throws IOException { //创建fos对象,//后边添加了true,表示 FileOutputStream fos = new FileOutputStream("C:\\Users\\DCF\\Desktop\\a.txt",true); //调用对象中的方法write,把数据写入到文件中 byte[] b={48,49,50,65,66,97,98}; fos.write(b,1,2);//指定偏移量的写入数据, fos.write("\r\n".getBytes());//写入换行字符 fos.write("您好".getBytes());//写入字节数组 for (int i = 0; i < 10; i++) { fos.write("你好".getBytes()); fos.write("\r\n".getBytes()); } //释放资源 fos.close(); System.out.println("写入成功;"); // int a=0; // boolean b1 = (a = 10) != -1; // System.out.println(a=10); } /* void write(byte[] b)将 b.length 个字节从指定 byte 数组写入此文件输出流中。 */ private static void demo02() throws IOException { //创建fos对象, FileOutputStream fos = new FileOutputStream("C:\\Users\\DCF\\Desktop\\1.txt"); //调用对象中的方法write,把数据写入到文件中 byte[] b={48,49,50,65,66,97,98}; fos.write(b); //释放资源 fos.close(); System.out.println("写入成功;"); } /* void write(int b)将指定字节写入此文件输出流。 */ private static void demo01()throws IOException { //创建fos对象, FileOutputStream fos = new FileOutputStream("C:\\Users\\DCF\\Desktop\\1.txt"); //调用对象中的方法write,把数据写入到文件中 fos.write(48); //释放资源 fos.close(); System.out.println("写入成功;"); }