티스토리 뷰
## 1바이트 출력 1 ##
## 1바이트 출력 2 ##
import java.io.*; public class _2_1 { public static void main(String[] args) throws IOException{ byte[] by = new byte[]{'R', 'a', 'i', 's', 'o', 'n'}; // 콘솔모드..... FileDescriptor.out: 콘솔에 출력 FileOutputStream fos1 = new FileOutputStream(FileDescriptor.out); fos1.write(by); fos1.write(by,2,1); fos1.write(65); fos1.close(); // 파일 모드..... true : 기존 내용에 추가 FileOutputStream fos2 = new FileOutputStream(new File("aaa.txt"), true); fos2.write(by); fos2.write(by,2,1); fos2.write(65); fos2.close(); } }
## 1바이트 출력 2 ##
import java.io.*; public class _2_2 { public static void main(String[] args) throws IOException{ FileOutputStream fos1 = new FileOutputStream(FileDescriptor.out); BufferedOutputStream bos1 = new BufferedOutputStream(fos1, 2048); //fo1내용의 2048바이트를 버퍼에 담았다가 한번에 출력하겠다. DataOutputStream dos1 = new DataOutputStream(bos1); // 바이트 뿐 아니라 다른 자료형 모두에 대해 출력하기 위함... dos1.writeBytes("abcde"); dos1.writeInt(20); dos1.writeDouble(20.253); dos1.flush(); dos1.writeChar('A'); dos1.close(); FileOutputStream fos2 = new FileOutputStream(new File("bbb.txt"), false); BufferedOutputStream bos2 = new BufferedOutputStream(fos2, 1024); DataOutputStream dos2 = new DataOutputStream(bos2); dos2.writeBytes("abcde"); dos2.writeInt(20); dos2.writeDouble(20.253); dos2.flush(); dos2.writeChar('A'); dos2.close(); } } // flush : 스트림을 close 하지 않고도 중간에 데이타를 내보내겠다. (중간중간에 flush - flush - ..... - close)
'dev > java' 카테고리의 다른 글
[15] Thread 만들기 기본.. (0) | 2008.09.27 |
---|---|
[16] 1바이트 입력 (0) | 2008.09.27 |
Inner Class (0) | 2008.09.27 |
4대 중첩 클래스 (0) | 2008.09.27 |
this는 자기자신의 객체.. (0) | 2008.09.25 |
공지사항