재귀 적으로 .exe 파일을 검색하는 Java를 사용하여 메소드를 작성하려고합니다. 내가 겪고있는 문제는 "C : \ Program Files (x86) \ Google \ CrashReports"디렉토리에있을 때이다.Java 파일 사용 권한 문제
나는이 파일 때문에 항상 NullPointerException을 얻는다. 필자는 재귀 적으로 검사 할 파일 목록에 파일을 추가하지 않거나 검사 할 파일 목록에 파일을 추가하는 경우 최소한 건너 뛸 수 있도록 노력했습니다.
내 코드가 잘못 되었기 때문에 이것은 논리적 인 오류 일 수 있습니다. 자바가 어떻게이 파일을 읽을 수 있다고 생각하는지에 대한 설명을 매우 높이 평가할 것입니다.
private static List<String> exefiles = new ArrayList<String>();
public void findExe(File rootDir) throws SecurityException, IOException{
List<File> files = new ArrayList<File>(Arrays.asList(rootDir.listFiles()));
List<File> directories = new ArrayList<File>();
Iterator<File> iterator = files.iterator();
if(files.size() > 0){
while(iterator.hasNext()){
File currentFile = iterator.next();
if(currentFile.getName().endsWith(".exe")){
exefiles.add(currentFile.getAbsolutePath());
}else if(currentFile.isDirectory()){
if(currentFile.canRead()){
System.out.println("We can read " + currentFile.getAbsolutePath());
if(currentFile.listFiles().length > 0){
System.out.println(currentFile.getAbsolutePath() + " has a length greater than 0");
directories.add(currentFile);
}else{System.out.println(currentFile.getAbsolutePath() + " does not have any files in it");}
}else{
System.out.println("Could not add " + currentFile.getAbsolutePath() + " to directories because it could not be read");
}
}else;
}
}
Windows에서 파일 속성을 열면 시스템 그룹과 관리자 그룹에는 모든 권한이 있지만 사용자 그룹에는 "특수 권한"만 있습니다.
Java 7은 java.nio.file 패키지를 통해 속성을 처리하는 더 쉬운 방법을 제공하지만이 옵션은 필자의 요구에 부적합하다는 것을 알고 있습니다.
변경할 수 있습니다'? 예외의 전체 스택 추적은 무엇입니까? – Jeffrey
발생한 문제에 대한 일반적인 설명이 아니라 전체 스택 추적을 게시하십시오. – chrylis