Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9090159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:18:43+00:00 2026-06-16T22:18:43+00:00

This post is a part 2 post of another one enquiry I made just

  • 0

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 :

1) new image into a certain directory, for example into C:\output

2)a whole directory(folder) of images, lets say from C:\importImages

into C:\output .

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.

This is the whole method for loading a whole directory.

    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();
    }
    }

and method for importing just a single file.

  private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here(for importing a single image to directory C:\output ).
--
    }

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:18:45+00:00Added an answer on June 16, 2026 at 10:18 pm

    The best way to learn something, try it yourself.
    I can show you the possibilities. Try these ways useful to insert in your code.

    Question : I am trying now to import a :

    • 1) new image into a certain directory, for example into C:\output

    Answer:

    How to copy file in Java from one directory to another is common requirement, given that there is no direct method in File API for copying files from one location to another.

    One way of copying file is reading from FileInputStream and writing same data to FileOutputStream to another directory.

    Thankfully you don’t need to reinvent wheel here, there are some open source library available which allows us to copy file in Java easily from one directory to another. One of such library is Apache commons IO which contains a class called FileUtils, which provides utility method for file related operation.

    Copy and rename file on different location

    FileUtils.copyFile

    FileUtils.copyFile(sourceFile, targetFile) can be used

        String source = "C:/output/myImage.jpg";
        //directory where file will be copied
        String target ="C:/importImages/";
    
        //name of source file
        File sourceFile = new File(source);
        String Filename = sourceFile.getName();
    
        File targetFile = new File(target+Filename);
    
        //copy file from one location to other
        FileUtils.copyFile(sourceFile, targetFile);
    

    Question : I am trying now to import a :

    • 2)a whole directory(folder) of images, lets say from C:\importImages
      into C:\output .

    Answer:

    What is the standard way nowadays to accomplish directory iteration with java?

    Best way to iterate through a directory in java?

    Add these ways in your code. Is not that hard.

    • Test for the file extension (.jpg .gif …)
    • Don’t forget to catch
    • NullPointerException – if source or destination is null
    • IOException – if source or destination is invalid
    • IOException – if an IO error occurs during copying
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This post is closely related to another one I posted some days ago .
So I saw this post which helped answer part of my question however now
This post will be heavy on images. I have created a custom ArrayAdapter and
So this is the second assignment in a beginner PHP class. One part of
I have a few modules, but I will focus on one in particular. This
Not sure about how to title this post. I just inherited a set of
OK I decided to retry it into another way.. This is my code the
Hey all, I am completely lost on this one. I found a code snippet
I'm trying to redirect users from one site to another but keep the part
I have this curl request below, which was successfully troubleshooted in another post. Right

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.