지난 File Test에 이어서 path와 file에 대해 이것저것 Check해보는 메소드들을 사용해보았습니다.
/**
* Created by 진우 on 2016-07-19.
*/
public class MyFileTest {
public static void main(String[] args) {
MyFileTest fileTest = new MyFileTest();
String path = "C:\\";
// String path = "C:\\sirius.txt";
fileTest.checkPath(path);
String fileName = "jinwoo.txt";
fileTest.checkFile(path, fileName);
fileTest.checkList(path);
}
public void checkPath(String path) {
File file = new File(path);
System.out.println(path + "is exists?" + file.exists());
System.out.println("Make " + path + " Result => " + file.mkdir());
System.out.println(path + "is Directory? => " + file.isDirectory());
System.out.println(path + "is File? => " + file.isFile());
System.out.println(path + "is hidden? => " + file.isHidden());
System.out.println(path + "can Read? => " + file.canRead());
System.out.println(path + "can Write? => " + file.canWrite());
System.out.println(path + "can Execute? => " + file.canExecute());
System.out.println(path + " last modified => " + file.lastModified());
System.out.println(path + " last modified => " + new Date(file.lastModified()));
System.out.println("Delete " + path + " result => " + file.delete());
}
public void checkFile(String path, String fileName) {
File file = new File(path, fileName);
try {
System.out.println("Create Result => " + file.createNewFile());
System.out.println("Absolute Path => " + file.getAbsolutePath());
System.out.println("Absolute File => " + file.getAbsoluteFile());
System.out.println("Canonical Path => " + file.getCanonicalPath());
System.out.println("Canonical File => " + file.getCanonicalFile());
System.out.println("Name => " + file.getName());
System.out.println("Path => " + file.getPath());
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
결과 창)
참고로, C 디렉토리는 권한이 필요하기 때문에 Make Result와 Delete는 false가 되었습니다.
(코드 내부에서 Delete는 조심해서 사용하시기 바랍니다. FileName을 중요한 파일로 테스트하시면 날릴수도 있습니다.)
'Programming > JAVA' 카테고리의 다른 글
JavaAPI(8) - Java IO(File Test) (0) | 2016.07.19 |
---|---|
JavaAPI(7) - Java Collection (Set Test) (0) | 2016.07.17 |
JavaAPI(6) - Java Collection (Queue Test) (0) | 2016.07.17 |
JavaAPI(5) - Java Collection (Map Test) (0) | 2016.07.17 |
JavaAPI(4) - Java Collection(ArrayList, Stack Test) (0) | 2016.07.17 |
WRITTEN BY