JAVA IO - 포맷 출력 흐름

917 단어 printstream
The PrintStream class enables you to write formatted data to an underlying OutputStream. For instance, writing int, long and other primtive data formatted as text, rather than as their byte values.
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;

public class PrintStreamTest {
	public static void main(String args[]) {
		try {
			OutputStream out = new FileOutputStream("helloworld.txt");
			
			PrintStream ps = new PrintStream(out);
			ps.printf("This is my %s Test", "PrintStream");
			ps.close();
			
			InputStream in = new FileInputStream("helloworld.txt");
			byte[] bs = new byte[1024];
			int len = -1;
			if((len = in.read(bs)) != -1){
				System.out.println(new String(bs, 0, len));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

좋은 웹페이지 즐겨찾기