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);

プロジェクトが移動した場合、パスを変更する必要があります。プロジェクト ディレクトリが変更されたときにターゲット パスを変更するにはどうすればよいですか?

4

1 に答える 1

0

この目的にはプロパティ ファイルを使用します。プロパティ値を変更する必要があります。

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

これらのプロパティを読み取るには、java.util.Propertiesを使用します。

mkyongで例を参照してください。

于 2013-01-03T06:33:24.013 に答える