2013. 7. 25. 16:54

Class File

java.lang.Object

java.io.File

 

 

 

● boolean isFile() : 파일인지 검사

 

 boolean isDirectory() : 디렉토리인지 검사

 

 long lastModified() : 마지막 수정일 리턴

 

 boolean canRead() : 읽기가능 검사

 

 boolean canWrite() : 쓰기가능 검사

 

 boolean isHidden() : 숨김파일인지 검사

 

 String getPath() : 상대경로

 

 String getAbsolutePath() : 절대경로

 

 String getName() : 파일이름 리턴

 

 Long length() : 파일의 바이트 크기 리턴

 

 boolean delete() : 파일삭제 //폴더를 대상으로 할 경우 자식파일이나 폴더가 존재하면 삭제할 수 없다.

 

 boolean renameTo(File destination)

 

1
2
3
4
File file = new File("d:\\AAA\\aaa.txt"); //원본파일
File dest = new File("d:\\BBB\\aaa.txt"); //이동할 경로
 
file.renameTo(dest);

 

 

 File[] listFiles() : 해당 경로의 자식파일|폴더를 File배열로 리턴

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
String path = "D:\\B_JAVA\\Example";
File dir = new File(path);
         
if (dir.exists())
{
File[] list = dir.listFiles();  //자식디렉토리 목록 & 파일목록
 
for (File i : list)
{
    if (list[i].isDirectory())
        System.out.prinln("폴더 : " +  list[i].getName());
 
        if (i.isFile())
        System.out.prinln("파일 : " +  i.getName());
}
}

 

 

● boolean mkdir() : 폴더 생성

 

 

1
2
3
4
5
6
File dir = new File("D:\\CCC");
 
if (!dir.exists()) { //존재하지 않으면
 
    dir.mkdir(); //생성
}


'java' 카테고리의 다른 글

Properties  (0) 2013.07.26
Arrays  (0) 2013.07.25
Class  (0) 2013.07.25
날짜관련  (0) 2013.07.25
Date, SimpleDateFormat  (0) 2013.07.25
Posted by 1+1은?