Language/JAVA
#7장 입출력 스트림
sohy
2021. 6. 28. 17:03
File 객체 생성
import java.io.File
File f = new File("c:\\test.txt");
File f = new File(File parent, String child); //parent 디렉터리에 child 이름의 디렉터리나 파일을 나타내는 File 객체 생성
[해당 경로에 실제로 파일이나 폴더가 있는지 확인]
boolean isExist = file.exists();
[exists() 메소드의 리턴 값이 false일 경우]
createNewFile() 새로운 파일 생성
mkdir() 새로운 폴더 생성
mkdirs() 경로상에 없는 모든 폴더 생성
File input / output
java.util.Scanne r 클래스 : 파일에서 text data 읽기
Scanner input = new Scanner(new File(filename));
java.io.PrintWriter 클래스 : 파일에 text data 쓰기
PrintWriter output = new PrintWriter(file);
output.print("");
for-each문
for (변수 : 배열) {
....
}