Note that there are some explanatory texts on larger screens.

plurals
  1. PONetBeans GUI Builder - Add a whole directory of images to another specific directory, so the images will be imported there
    primarykey
    data
    text
    <p>I am currently building an application, where I want a whole directory to be imported in another one. I am working with apache commons.io library that you need to import a s a jar file.</p> <p>Let's say from a directory that I will choose with a JfileChooser from GuiBuilder Netbeans into C:\output. I want all the images to be imported there. My code is not running. When I am pressing JButton2 ( the button responsible for loading a directory I get an exception </p> <blockquote> <blockquote> <p>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at WebAppImg.jButton2ActionPerformed(WebAppImg.java:141) ( The second line points out to : String filename = f.getAbsolutePath(); )</p> </blockquote> </blockquote> <p>copyDirectoryToDirectory method maybe. But my thoughts on doing that was that when putting FileSelectionMode to be Directories_Only that the absolute path would be something like C:\importFile and not C:\importFile\image1.jpg for example so it would not be wrong. But maybe this is the mistake?</p> <p>So far, this is my code.</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:\images1 into C:\output ). JFileChooser chooser = new JFileChooser(); chooser = new JFileChooser(); //chooser.setCurrentDirectory(new java.io.File(".")); //chooser.setDialogTitle(choosertitle); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); //chooser.showOpenDialog(null); //chooser.setAcceptAllFileFilterUsed(false); File f = chooser.getSelectedFile(); String filename = f.getAbsolutePath(); try { File srcDir = new File(filename); File destDir = new File("C:/output/"); FileUtils.copyDirectoryToDirectory(srcDir, destDir); } catch (Exception ex) { ex.printStackTrace(); } } </code></pre>
    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. This table or related slice is empty.
 

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