파일에서 한줄 읽기

BufferedReader br = new BufferedReader(new FileReader("/..../file"));
String tmp = br.readLine();
br.close();

파일에 쓰기

String tmp = "my file";
FileOutputStream out = new FileOutputStream("/..../path");
out.write(tmp.getBytes());
out.close();

파일 혹은 디렉토리가 있는지 확인하기

 File f = new File("/../path");
 if(f.exists()){
 	// 존재함
 }

파일 혹은 디렉토리인지 확인하기

File f = new File("/..../path");
if(f.isDirectory()){
	// 디렉토리
}
else if(f.isFile()){
	// 파일
}

파일 혹은 디렉토리 삭제하기

File f = new File("/...../path");
f.delete();

디렉토리 만들기

File f = new File("/...../path");
f.mkdir();
//f.mkdirs(); // 상위 디렉토리가 없을 경우 자동으로 생성해줌

 

728x90
반응형

+ Recent posts