2013-11-25 34 views
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"); 
      } 
     } 
+0

如果'.someApp'目錄不存在會怎麼樣? – MadProgrammer

+0

'.someApp'在第一次運行時創建。並且在創建後手動檢查權限。另外由於某些原因,其他文件正在保存在那裏,但不是'.db'文件 – Alosyius

+0

您是否檢查'.db'文件類型是否爲系統文件並且在Win Server上默認隱藏? –

回答

2

如果該文件不能被創建,你應該得到一個錯誤。檢查應用程序的錯誤處理。

如果你沒有得到一個,則該文件可能被創建,但不是你指望它。

我建議一些記錄添加到代碼:

log.debug("path="+myAppDir.getAbsolutePath()); 
log.debug("url="+databaseFileLocation); 

或者,使用Process Monitor看到你的應用程序在做。

相關問題