IO(입출력) : Input과 Output의 약자, 컴퓨터 내부 또는 외부 장치와 프로그램 간의 데이터를 주고 받는 것
장치와 입출력을 위해서는 하드웨어 장치에 직접 접근이 필요한데 다양한 매체에 존재하는 데이터들을
사용하기 위해 입출력 데이터를 처리할 공통적인 방법으로 스트림 이용
public static void main(String[] args) {
// 간단하게 파일 만들기
// java.io.File 클래스 사용
try{
//1.경로지정을 하지 않은 상태로 파일 생성 -> 현재 project폴더에 파일생성
File f1 = new File("test.txt"); //만들고자하는 파일명 지정
f1.createNewFile();
//2. 경로지정한 상태로 파일 생성
File f2 = new File("C:\\folder\\test.txt");//경로 지정 (존재하지 않는 경로 지정하면 IOException 예외 발생)
f2.createNewFile();
//3. 폴더먼저 만들고 파일까지 만들어지게하기
File folder1 = new File("C:\\folder2");
folder1.mkdir();
File f3 = new File("C:\\folder2\\test.txt");
f3.createNewFile();
//----------------------------------------
File folder = new File("parent");
folder.mkdir();
File file = new File("parent\\person.txt");
file.createNewFile();
System.out.println(folder.isFile());
System.out.println(file.isFile());
System.out.println("파일명 : "+ file.getName());
System.out.println("절대경로 : "+ file.getAbsolutePath());
System.out.println("파일의 용량 : "+file.length());
System.out.println("상위폴더 : "+ file.getParent());
}catch(IOException e){
e.printStackTrace(); // 강제로 오류난 이력 추적
}
System.out.println("프로그램을 종료합니다.");
'JAVA' 카테고리의 다른 글
12. IO (IntputOutput) _문자기반 Stream (0) | 2022.11.08 |
---|---|
12. IO (IntputOutput) _바이트기반Stream (0) | 2022.11.07 |
11.Exception_ CheckedException (0) | 2022.11.07 |
11. Exception_ UnCheckedException (0) | 2022.11.07 |
10. API _ Date (0) | 2022.11.04 |