자바의 기본 데이터 타입을 Stream에 직접 기록이 가능
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class DataInputOutputTest {
public static void main(String[] args) throws Exception{
char c = 'A';
char c1 = 'x';
String str = "study";
String str1 = "java";
String file = "C:/Users/sharkmino/Desktop/Music_2.txt";
DataInputStream in = null;
DataOutputStream out = null;
FileOutputStream fout = new FileOutputStream(file);
out = new DataOutputStream(fout);
out.writeChar(c);
out.writeUTF(str);
out.close();
System.out.println("c:" + c + " c1:" + c1 + " str:" + str + " str1:" + str1);
FileInputStream fin = new FileInputStream(new File(file));
in = new DataInputStream(fin);
c1 = in.readChar();
str1 = in.readUTF();
in.close();
System.out.println("c:" + c + " c1:" + c1 + " str:" + str + " str1:" + str1);
}
}
'프로그래밍 정리 > 자바' 카테고리의 다른 글
SequenceInputStream (0) | 2013.06.01 |
---|---|
BufferedInputStream와 BufferedOutputStream (0) | 2013.06.01 |
StreamTokenizer (0) | 2013.06.01 |
RandomAccessFile (0) | 2013.05.31 |
InputStream in.read() -1 (0) | 2013.05.31 |