【问题标题】:copying in same directory of the project in java?在java中复制项目的同一目录?
【发布时间】:2012-12-17 12:39:57
【问题描述】:
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 copying


【解决方案1】:

为此使用属性文件,您需要做的是更改属性值。

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

使用java.util.Properties 读取这些属性。

请参阅mkyong 上的示例。

【讨论】:

  • 如果我的项目目录改变了怎么办?如果我清理并构建程序?
  • 如果你改变你的目录,你会在你的属性文件中更新app.home
猜你喜欢
  • 2016-04-02
  • 1970-01-01
  • 2013-04-26
  • 1970-01-01
  • 2012-01-07
  • 2010-11-11
  • 1970-01-01
  • 1970-01-01
  • 2017-08-14
相关资源
最近更新 更多