자바 파일
파일 처리는 모든 응용 프로그램의 중요한 부분입니다.
Java에는 파일을 생성, 읽기, 업데이트 및 삭제하는 여러 방법이 있습니다.
자바 파일 처리
패키지 의 File
클래스를 사용하면 파일 작업을 할 수 있습니다.java.io
클래스 를 사용하려면 File
클래스의 개체를 만들고 파일 이름 또는 디렉터리 이름을 지정합니다.
예시
import java.io.File; // Import the File class
File myObj = new File("filename.txt"); // Specify the filename
패키지가 무엇인지 모르는 경우 Java 패키지 자습서 를 읽으십시오 .
이 File
클래스에는 파일을 만들고 정보를 얻는 데 유용한 여러 메서드가 있습니다. 예를 들어:
Method | Type | Description |
---|---|---|
canRead() |
Boolean | Tests whether the file is readable or not |
canWrite() |
Boolean | Tests whether the file is writable or not |
createNewFile() |
Boolean | Creates an empty file |
delete() |
Boolean | Deletes a file |
exists() |
Boolean | Tests whether the file exists |
getName() |
String | Returns the name of the file |
getAbsolutePath() |
String | Returns the absolute pathname of the file |
length() |
Long | Returns the size of the file in bytes |
list() |
String[] | Returns an array of the files in the directory |
mkdir() |
Boolean | Creates a directory |
다음 장에서 파일을 만들고, 쓰고, 읽고, 삭제하는 방법을 배웁니다.