这篇文章是我几天前进行的另一项调查的第 2 部分。然后使用此代码,我将放在最后,通过 JButton1,我能够附加一个文件,并使其在应用程序北部和东部的窗口中可见。我现在正在尝试导入:
1) 将新图像放入某个目录,例如放入 C:\output
2)图像的整个目录(文件夹),可以说来自 C:\importImages
进入 C:\output 。
为此,我假设我在 C:\importImages 目录中有一些图像。下面,这些是我需要填写的 2 个代码示例,以便我想要工作。尝试加载目录的第一种方法无法运行。我认为它的错误可能与 GUI Builder 中的 Filechooser 按钮有关。
这是加载整个目录的完整方法。
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:(for importing a whole directory(folder) from C:\importImages into C:\output ).
JFileChooser chooser = new JFileChooser();
chooser = new JFileChooser();
File f = chooser.getSelectedFile();
String filename = f.getAbsolutePath();
try {
ImageIcon ii=new ImageIcon(scaleImage(250, 250, ImageIO.read(new File(filename))));//get the image from file chooser (directories)
//jLabel1.setIcon(ii);
File srcDir = new File(filename);
File destDir = new File("C:/output/");
FileUtils.copyDirectoryToDirectory(srcDir, destDir);
}
catch (Exception ex) {
ex.printStackTrace();
}
}
以及仅导入单个文件的方法。
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here(for importing a single image to directory C:\output ).
--
}
提前致谢!