2013-01-03 19 views
1
int reval = fcCari.showOpenDialog(this); 
String sourcePath = fcCari.getSelectedFile().getAbsolutePath(); 
String targetPath = "C:\\Users\\nadzar\\Downloads\\Compressed\\JavaSQLite\\resource\\"; 
    targetPath += fcCari.getSelectedFile().getName(); 
    if ((reval == JFileChooser.APPROVE_OPTION)) { 
      File source = new File(sourcePath); 
      File target = new File(targetPath); 
      copyFile(source, target); 
      targetPathFoto=targetPath; 
      tambahFoto(targetPathFoto); 
    } 
    else{ 
     JOptionPane.showMessageDialog(rootPane, "Batal Menambahkan Foto"); 
     tambahFoto(this.targetFoto); 
    } 
    System.out.println(targetPathFoto); 

如果我的項目已移動,則路徑必須更改。 我問我的項目目錄改變時目標路徑如何改變?複製在java項目的同一目錄中?

+0

類似[this](http://stackoverflow.com/questions/778187/getting-directory-path-to-class-file-containing-main)? –

回答

0

爲此目的使用屬性文件,您需要做的是更改屬性值。

# app home, build absolute paths in code using this path 
app.home=path_to_home_directory 

使用java.util.Properties來讀取這些屬性。

請參閱mkyong的示例。

+0

如果我的項目目錄改變了,如果我清理並建立程序? – user1944789

+0

如果你改變你的目錄,你會更新屬性文件中的'app.home' –