61

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);
				else
					System.out.println(Character.toUpperCase((char)c));
			}
			
			System.out.println();
			
			bs.reset();
		}
	}
}

//output:
//	a
//	b
//	c
//	d
//	e
//
//	A
//	B
//	C
//	D
//	E




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

阅读更多
博主设置当前文章不允许评论。

没有更多推荐了,返回首页

关闭
关闭
关闭