61

来源:互联网 发布:mac如何连续选中 编辑:程序博客网 时间:2024/04/29 22:21
package com.haizhitao.io2;import java.io.FileOutputStream;import java.io.OutputStream;public class OutputStreamTest1{public static void main(String[] args) throws Exception{OutputStream os = new FileOutputStream("c:/haizhitao1.txt", true);String str = "  haizhitao1";byte[] buffer = str.getBytes();os.write(buffer);os.close();}}package com.haizhitao.io2;import java.io.BufferedOutputStream;import java.io.FileOutputStream;import java.io.OutputStream;public class BufferedOutputStreamTest1{public static void main(String[] args) throws Exception{OutputStream os = new FileOutputStream("c:/haizhitao2.txt");BufferedOutputStream bos = new BufferedOutputStream(os);bos.write("www.baidu.com".getBytes());bos.close();}}package com.haizhitao.io2;import java.io.ByteArrayInputStream;public class ByteArrayInputStreamTest1{public static void main(String[] args){String str = "abcde";byte[] b = str.getBytes();ByteArrayInputStream bs = new ByteArrayInputStream(b);for(int i = 0; i < 2; i++){int c;while(-1 != (c = bs.read())){if(i == 0)System.out.println((char)c);elseSystem.out.println(Character.toUpperCase((char)c));}System.out.println();bs.reset();}}}//output://a//b//c//d//e////A//B//C//D//Epackage com.haizhitao.io2;import java.io.ByteArrayOutputStream;import java.io.FileOutputStream;import java.io.OutputStream;public class ByteArrayOutputStreamTest1{public static void main(String[] args) throws Exception{ByteArrayOutputStream f = new ByteArrayOutputStream();byte[] buffer = "hello world welcome".getBytes();f.write(buffer);OutputStream os = new FileOutputStream("c:/test.txt");f.writeTo(os);f.close();os.close();}}

原创粉丝点击