객체
read() 메소드
byte 단위 입출력기 코드
public class ByteIOExam1 {
public static void main(String[] args){
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream("src/javaIO/exam/ByteExam1.java");
fos = new FileOutputStream("byte.txt");
int readData = -1;
while((readData = fis.read())!= -1){
fos.write(readData);
}
} catch (Exception e) {
// TODO Auto-generated catch blocke.printStackTrace();
}finally{
try {
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch blocke.printStackTrace();
}
try {
fis.close();
} catch (IOException e) {
// TODO Auto-generated catch blocke.printStackTrace();
}
}
}
}
fos.write(n) : 저장된 int 값의 가장 낮은 1바이트 파일에 쓰임.
int n = 65; // ASCII 코드에서 'A'에 해당하는 값 fos.write(n); // 파일에 'A'를 씁니다.