반응형
1. FileOutputStream으로 바이너리 파일 쓰기
package hello;
import java.io.*;
public class FileOutputStreamEx {
public static void main(String[] args) {
byte b[] = {7, -51, 3, 4, -1, -2, 24};
try {
FileOutputStream fout = new FileOutputStream("c:\\Temp\\test.out");
for(int i=0; i<b.length; i++) {
fout.wait(b[i]); //배열 b의 바이너리를 그대로 기록
}
fout.close();
} catch (Exception e) {
System.out.println("c:\\Temp\\test.out을 저장하였습니다.");
}
}
}
2. 코드 차이분석 24 | - FileInputStream
1)
package hello;
import java.io.FileInputStream;
public class Ex10_09 {
public static void main(String[] args) throws Exception {
FileInputStream fis = new FileInputStream("c:/Temp/data1.txt");
int ch;
while((ch = fis.read()) != -1) {
System.out.print((char) ch);
}
fis.close();
}
}
File Read Sample ??´?´?.
2)
package hello;
import java.io.FileInputStream;
public class Ex10_09 {
public static void main(String[] args) throws Exception {
FileInputStream fis = new FileInputStream("c:/Temp/data1.txt");
int ch;
while((ch = fis.read()) != -1) {
System.out.println((char) ch);
}
fis.close();
}
}
File Read Sample 입니다.
반응형
'JAVA' 카테고리의 다른 글
[자바] Thread (0) | 2020.01.19 |
---|---|
[자바]이벤트와 메뉴 (0) | 2020.01.18 |
[자바] Gui 프로그래밍 (0) | 2020.01.18 |