2014-05-19 3 views
0

"Run"을 클릭하여 프로젝트를 실행할 때 Netbeans에서 만드는 임시 디렉토리의 위치를 ​​가져 오려고 시도하면 dist 디렉토리에 run1017994493과 같은 파일이 생성됩니다. 그런 다음디렉토리가 존재하지 않는 이유는 무엇입니까?

는 그것이이 코드를 실행 빌드 거의 즉시 :

String fileloc = SQLite.class.getProtectionDomain().getCodeSource().getLocation().getPath(); 
String location = fileloc.substring(0, fileloc.lastIndexOf("/")); 
File f = new File(location); 
System.out.println(location); 
System.out.println(f.exists()); 

아웃풋 :

/C:/Users/rnaddy/Documents/NetBeansProjects/Phantom%20Browser/dist/run1017994493 
false 

가 왜 디렉토리가 존재하지 않음을 말하고있다?

가 나는 다음 두 줄이 휴식을 일으키는 생각 :

Class.forName("org.sqlite.JDBC"); 
conn = DriverManager.getConnection("jdbc:sqlite:" + location + "/phantom.db"); 
+1

% 20을 공백으로 바꾸어보세요. – Kakarot

+0

Genius! 그것이 원인이었습니다! –

답변

1

하기 전에, 당신은 제목 제거해야 "/"다음 "20 %"또는 이와 유사한 것들의 모든 발행 수는 해당 문자로 교체해야합니다 :

String loc = ... 
if (isWindows()) { 
    //remove heading slash 
    loc = loc.replaceAll("^/", ""); 
} 
loc = URLDecoder.decode (loc, "UTF-8"); // this will replace all characters like "%20" with something like " " 
-1

난 당신이 작성 후 파일을 닫습니다한다고 생각합니다.

f.close(); 

그냥 출력 라인 첫째

+1

File에 가까운 방법이 없다고 확신합니다. – MadProgrammer

관련 문제