package ch03_reader;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class ReaderIn {
public static void main(String[] args) throws IOException {
File path = new File(File.separator + "Users" + File.separator + "simpangyo" + File.separator + "FinTech_SPG" + File.separator + "IOjava");
if(path.exists() == false) {
path.mkdir();
System.out.println("폴더 생성.");
}
File mf = new File(path, "reader.txt");
if(mf.createNewFile()) {
System.out.println(mf.getName() + "생성.");
} else {
System.out.println(mf.getName() + " 파일이 이미 있습니다.");
}
// 데이터 전송 통로 생성
FileInputStream fis = new FileInputStream(mf);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);
int ia = dis.readInt();
double dd = dis.readDouble();
String sd = dis.readUTF();
System.out.println("ia : " + ia);
System.out.println("dd : " + dd);
System.out.println("sd : " + sd);
dis.close();
}
}
package ch03_reader;
import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class ReaderOut {
public static void main(String[] args) throws IOException {
File path = new File(File.separator + "Users" + File.separator + "simpangyo" + File.separator + "FinTech_SPG" + File.separator + "IOjava");
if(path.exists() == false) {
path.mkdir();
System.out.println("폴더 생성.");
}
File mf = new File(path, "reader.txt");
if(mf.createNewFile()) {
System.out.println(mf.getName() + " 생성.");
} else {
System.out.println(mf.getName() + " 파일이 이미 있습니다.");
}
// 데이터 전송 통로 생성
FileOutputStream fos = new FileOutputStream(mf);
BufferedOutputStream bos = new BufferedOutputStream(fos);
DataOutputStream dos = new DataOutputStream(bos);
dos.writeInt(123);
dos.writeDouble(5.6);
dos.writeUTF("buffer 데이터");
dos.close();
}
}