0
我的應用程序必須創建一個.db文件才能工作。如果這個文件不存在,我的應用程序會創建它。但是在某些版本的Windows上,例如Windows Server,該文件永遠不會創建。另外我確定這個文件夾有完整的讀/寫權限。未在Windows Server上創建Java文件
這是我的代碼來創建該文件:
String databaseFileLocation = "";
String fileSeparator = System.getProperty("file.separator");
String homeDir = System.getProperty("user.home");
File myAppDir = new File(homeDir, ".someApp");
databaseFileLocation = "jdbc:sqlite:" + myAppDir + fileSeparator + "history_" + userID + ".db";
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection(databaseFileLocation);
Statement stat = conn.createStatement();
stat.executeUpdate("CREATE TABLE IF NOT EXISTS chatHistory (channelID, sender, message, recipient, time);");
它工作在Win 7,贏服務器上其不被創建Win XP的Vista的勝利,等等。但是。即使我有權限。
任何想法可能是造成這個?
編輯
這是我如何創建目錄:
String homeDir = System.getProperty("user.home");
File myAppDir = new File(homeDir, ".someApp");
// if the directory does not exist, create it
if (!myAppDir.exists()) {
System.out.println("creating directory: " + myAppDir);
boolean result = myAppDir.mkdir();
if (result) {
System.out.println("DIR created");
}
}
如果'.someApp'目錄不存在會怎麼樣? – MadProgrammer
'.someApp'在第一次運行時創建。並且在創建後手動檢查權限。另外由於某些原因,其他文件正在保存在那裏,但不是'.db'文件 – Alosyius
您是否檢查'.db'文件類型是否爲系統文件並且在Win Server上默認隱藏? –