Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- java
- unity
- oracle
- C/C++
- 입출력
- 예외던지기
- Interface
- Class함수
- 스레드
- 상수변수
- singleton
- Exception
- db
- c#
- Thread
- cocos2d-x
- 데이터베이스
- interface상속
- cocos2d
- Stack
- 반복문
- c++
- 동기화블럭
- 프로그래밍
- cocos2dx
- 문자열
- 데이터타입
- 예외처리
- c++게임엔진
- 게임엔진
Archives
- Today
- Total
초보 프로그램 개발자
[ 5주차 ] Java - FileFilter 본문
FileFilter
- 특정 경로 폴더 안의 내용을 모두 읽어오는 Interface
- Interface 이기 때문에 무조건 accept를 오버라이드 해주어야 한다.
package com.day19;
import java.io.File;
import java.io.FileFilter;
// 특정 경로 폴더안의 내용을 모두 읽어오는 클래스
class MyFileList implements FileFilter{
private File f;
public MyFileList(String path) {
f = new File(path);
}
public void result() {
try {
if(!f.exists()) { // 파일이 없을경우
System.out.println("파일이 없습니다.");
}
System.out.println("경로 : " + f.getAbsolutePath());
System.out.println("파일크기 : " + f.length());
// 파일이 아니라 폴더인 경우
if(f.isDirectory()) {
File[] lists = f.listFiles(this);
// 폴더내용 출력
System.out.println("\n폴더 내용....");
for(int i=0; i<lists.length; i++) {
System.out.print("폴더이름 : " + lists[i].getName());
System.out.println("\t폴더크기 : " + lists[i].length());
}
}
System.out.println("-----------------------");
System.out.println("\n디렉토리 내용...");
// File.listRoots() 는 드라이브를 표시 (c:, d:...)
File[] root = File.listRoots();
for(int i=0; i<root.length; i++) {
System.out.println(root[i].getPath());
}
} catch (Exception e) {
System.out.println(e.toString());
}
}
@Override
public boolean accept(File pathname) {
return pathname.isFile() || pathname.isDirectory();
}
}
public class Test13 {
public static void main(String[] args) {
MyFileList mf = new MyFileList("c:\\");
mf.result();
}
}
'교육 일지 > java' 카테고리의 다른 글
[ 5주차 ] Java - Frame (0) | 2023.06.05 |
---|---|
[ 5주차 ] Java - 객체의 직렬화 (0) | 2023.06.01 |
[ 5주차 ] Java - 버퍼를 사용해서 파일을 읽어오기 (0) | 2023.05.31 |
[ 5주차 ] Java - File (0) | 2023.05.31 |
[ 5주차 ] Java - 파일 입출력 (0) | 2023.05.31 |