Note that there are some explanatory texts on larger screens.

plurals
  1. POJava GUI builder - importing an image to a directory and a given directory with JFileChooser to a standard directory
    primarykey
    data
    text
    <p>This post is a part 2 post of another one enquiry I made just days ago. Then with this code I will put last and through JButton1 I was able to attach a file and make it visible in a window north and east to the application. I am trying now to import a :</p> <p>1) new image into a certain directory, for example into C:\output </p> <p>2)a whole directory(folder) of images, lets say from C:\importImages</p> <p>into C:\output .</p> <p>For this I assume that I have some images in C:\importImages directory. Below , these are the 2 code samples that I need to fill in in order this thing that I want to work. This first method trying to load directories fails to run. I think that maybe its fault has to do something with Filechooser button from GUI Builder.</p> <p>This is the whole method for loading a whole directory.</p> <pre><code> 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(); } } </code></pre> <p>and method for importing just a single file.</p> <pre><code> private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here(for importing a single image to directory C:\output ). -- } </code></pre> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COPlease do not change your question in this way. Visitors can not know which of the original information, the answer relates. Please change the "question" back to their original state. And post a new question.
      singulars
    2. CO1.) You can not pass a directory to the function scaleImage() it's impossible to scale a directory !!! `chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);` and so your code will not come to the next error. 2.) If you change JFileChooser to point to a file. `File srcDir = new File(filename);` Is not what you want! Because filename contains the whole path like C:/choosenDir/myImageFile.jpg and that's not allowed in the function "copyDirectoryToDirectory" `if (srcDir.exists() && srcDir.isDirectory() == false) {throw new IllegalArgumentException("Source '" "' is not a directory")`
      singulars
    3. COYou are right Mosquito. I will post another question in a bit about directory only. I changed the question back to its normal state. Please anwser that question that I will make if I can. Thanks for your help in this one.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload