example7_3.java

来自「《Java程序设计与应用》-张仕斌-源程序 《Java程序设计与应用》-张仕斌」· Java 代码 · 共 49 行

JAVA
49
字号
/*
 * Example7_3.java
 *
 * Created on 2006年9月15日, 下午5:01
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package example7_3;
import java.io.*;
/**
 *
 * @author Administrator
 */
public class Example7_3 {
    
    /** Creates a new instance of Example7_3 */
    public Example7_3() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException{
        // TODO code application logic here
		ByteArrayOutputStream f = new ByteArrayOutputStream();
		String s = "This should end up in the array";
		byte buf[] = s.getBytes();
		f.write(buf);
		System.out.println("Buffer as a string");
		System.out.println(f.toString());
		System.out.println("Into array");
		byte b[] = f.toByteArray();
			for (int i=0;i<b.length;i++)
                            System.out.print((char)b[i]);
		System.out.println("\nTo an OutputStream()");
		OutputStream f2 = new FileOutputStream("test.txt");
		f.writeTo(f2);f2.close();
		System.out.println("Doing a reset");
		f.reset();
		for (int i=0; i<3; i++)
			f.write('X');
		System.out.println(f.toString());
	
    }
    
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?