gpt4 book ai didi

java - 复制从 jfilechooser 中选择的文件

转载 作者:行者123 更新时间:2023-12-01 12:27:16 26 4
gpt4 key购买 nike

我正在使用文件选择器来选择图像文件。单击打开按钮时,我想将图像复制到我的项目文件夹。代码没有显示任何错误,但没有任何反应。没有复制任何内容。

 if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = jFileChooser1.getSelectedFile();
File target = new File("/"+file.getName());
try {
Files.copy(file.toPath(),target.toPath(),REPLACE_EXISTING);
} catch (IOException ex) {
Logger.getLogger(detail1.class.getName()).log(Level.SEVERE, null, ex);
}

}

我在 File target = new File("/"+file.getName()); 中使用了 ',' 而不是 '+' code> 但运气不佳,这里有什么问题吗?

最佳答案

这解决了我的问题:
文件目标 = new File(System.getProperty("user.dir")+"/images",file.getName());

关于java - 复制从 jfilechooser 中选择的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26222686/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com