Java
[JAVA] 내 PC 디스크 확인
로니콜먼
2020. 8. 28. 11:11
- File[] listRoots() : 하드디스크 경로를 반환
- String getAbsolutePath() : 파일의 절대경로를 문자열로 반환
File[] roots = File.listRoots();
String[] drives = new String[roots.length]; // 드라이브 명
int i = 0;
for (File root : roots) {
drives[i] = root.getAbsolutePath();
i++;
}
File형 배열 roots 변수에 File.listRoots() 메서드를 통해 하드디스크 경로를 반환한다
반환된 하드디스크 경로를 통해 .getAbsolutePath() 메서드로
String[] 배열에 루트 드라이버의 절대 경로를 반환