
파일 경로
상대 경로에서 study부터 시작하지 않은 이유는 기준이 study이기 때문에(project폴더)
study기준으로 파일이 실행 되고 있는 거라 적어주지 않아도 된다.
버퍼 스트림
bufferd
package ex15;
import java.io.*;
// 상대 경로: 실행되는 위치(프로젝트 폴더)를 기반으로 경로 정하는 것. (실행이 어디에서 되고있는지)
// 일반적으로 자바에서는 Project다. 즉 study가 된다.
// 절대 경로: 루트에서 부터 경로를 찾는 것
// 윈도우: C:\\workspace\\hello.txt
// 맥, 리녹스: /worksapce/hello.txt
public class StreamEx05 {
public static void main(String[] args) {
try {
//BufferedReader br = new BufferedReader(new FileReader("D:\\workspace\\java_lec\\study\\src\\ex15\\hello.txt")); //절대 경로
BufferedReader br = new BufferedReader(new FileReader("src\\ex15\\hello.txt")); // 상대 경로
String line = br.readLine();
System.out.println(line);
BufferedWriter bw = new BufferedWriter(new FileWriter("input.txt"));
bw.write("안녕");
bw.write("반가워\n");
bw.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Share article