我试图获得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
为什么说,目录不存在?
我相信这是造成下列2条防线:
Class.forName("org.sqlite.JDBC");
conn = DriverManager.getConnection("jdbc:sqlite:" + location + "/phantom.db");
尝试用空格替换%20 – Kakarot
天才!这是原因! –