import java.io.File;
public class GetFileList {
public static void main(String[] args) {
File myDir = new File("C:/Users/lssang/Desktop/이미지"); // 디렉토리의 객체생성
System.out.println(myDir.getAbsolutePath()); // 디렉토리의 절대경로
System.out.println(myDir.getParent()); // 부모디렉토리
String fileName = myDir.getName(); // 파일 이름
String fileExtention = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length());
// 파일 확장자
File[] contents = myDir.listFiles(); // 디렉토리의 내용을 가져온다
// 디렉토리의 내용 목록출력
if (contents != null) { // contents가 null값이 아닐경우(디렉토리에 내용이 있을경우)디렉토리의 내용출력
for (int i = 0; i < contents.length; i++) {
System.out.println(contents[i].getName());
}
} else { // contents가 null일 경우(디렉토리에 내용이 없을경우)
System.out.println(myDir.getName() + " is not a directory");
}
System.exit(0);
}
}
'~ 2014 > JAVA & ANDROID' 카테고리의 다른 글
ANDROID :: 환경설정창 만들기 preferenceScreen (0) | 2013.07.16 |
---|---|
JAVA :: 모니터 해상도에 따른 중앙값 얻기 (0) | 2013.07.13 |
JAVA:: JsonObject, JsonArray (0) | 2013.07.12 |
JAVA:: ip주소 가져오기 (0) | 2013.07.12 |
ANDROID:: Toast (0) | 2013.07.12 |