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 8169619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:54:00+00:00 2026-06-06T20:54:00+00:00

I want to read all the images in a folder using Java. When: I

  • 0

I want to read all the images in a folder using Java.

When: I press a button in the Java application,
It should:

  • ask for the directory’s path in a popup,
  • then load all the images from this directory,
  • then display their names, dimension types and size.

How to proceed?

I have the code for read the image and also for all image in the folder but how the things i told above can be done?

Any suggestion or help is welcome! Please provide reference links!

  • 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-06T20:54:02+00:00Added an answer on June 6, 2026 at 8:54 pm

    Untested because not on a machine with a JDK installed, so bear with me, that’s all typed-in “as-is”, but should get you started (expect a rush of downvotes…)

    Loading all the Images from a Folder

    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.FilenameFilter;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    
    public class Test {
    
        // File representing the folder that you select using a FileChooser
        static final File dir = new File("PATH_TO_YOUR_DIRECTORY");
    
        // array of supported extensions (use a List if you prefer)
        static final String[] EXTENSIONS = new String[]{
            "gif", "png", "bmp" // and other formats you need
        };
        // filter to identify images based on their extensions
        static final FilenameFilter IMAGE_FILTER = new FilenameFilter() {
    
            @Override
            public boolean accept(final File dir, final String name) {
                for (final String ext : EXTENSIONS) {
                    if (name.endsWith("." + ext)) {
                        return (true);
                    }
                }
                return (false);
            }
        };
    
        public static void main(String[] args) {
    
            if (dir.isDirectory()) { // make sure it's a directory
                for (final File f : dir.listFiles(IMAGE_FILTER)) {
                    BufferedImage img = null;
    
                    try {
                        img = ImageIO.read(f);
    
                        // you probably want something more involved here
                        // to display in your UI
                        System.out.println("image: " + f.getName());
                        System.out.println(" width : " + img.getWidth());
                        System.out.println(" height: " + img.getHeight());
                        System.out.println(" size  : " + f.length());
                    } catch (final IOException e) {
                        // handle errors here
                    }
                }
            }
        }
    }
    

    APIs Used

    This is relatively simple to do and uses only standard JDK-packaged classes:

    • File
    • FilenameFilter
    • BufferedImage
    • ImageIO

    These sessions of the Java Tutorial might help you as well:

    • Reading/Loading an Image
    • How to Use Icons
    • How to Use File Choosers

    Possible Enhancements

    • Use Apache Commons FilenameUtils to extract files’ extensions
    • Detect files based on actual mime-types or content, not based on extensions
    • I leave UI code up to you. As I’m unaware if this is homework or not, I don’t want to provide a full solution. But to continue:
      • Look at a FileChooser to select the folder.
      • I assume you already know how to make frames/windows/dialogs.
      • Read the Java Tutorial How to Use Icons sections, which teaches you how to display and label them.
    • I left out some issues to be dealt with:
      • Exception handling
      • Folders with evil endigs (say you have a folder “TryMeIAmEvil.png”)

    By combining all of the above, it’s pretty easy to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read all thumbnails from a folder with images in Windows XP.
I want to read a folder for all the files and programmatically print them
I am trying to get all images in my assets folder using the codes
I want to store images into sql using c# application. So I have this
I carefully read the question 'Official way to ask jQuery wait for all images
I want to read all the contacts from the phone but i am unable
I just want what my title says.I have already read all the previous similar
I want to read the company table and take out all possible suffixes from
Basically I want to read and write to a file then save all the
i want to read from a text file in C#. But I want all

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.