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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:40:01+00:00 2026-05-26T05:40:01+00:00

I know how to copy a file from one directory to another, what I

  • 0

I know how to copy a file from one directory to another, what I would like help on is copy a file with .jpg or .doc extension.

So for example.

Copy all files from D:/Pictures/Holidays

Scanning all folders in the above path and transfer all jpg’s to a destination provided.

  • 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-05-26T05:40:01+00:00Added an answer on May 26, 2026 at 5:40 am

    This works, but the file ‘copy(File file, File outputFolder)’ method could be enhanced for large files:

    package net.bpfurtado.copyfiles;
    
    import java.io.File;
    import java.io.FileFilter;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
    
    public class CopyFilesFromType
    {
        public static void main(String[] args)
        {
            new CopyFilesFromType().copy("jpg", "C:\\Users\\BrunoFurtado\\Pictures", "c:/temp/photos");
        }
    
        private FileTypeOrFolderFilter filter = null;
    
        private void copy(final String fileType, String fromPath, String outputPath)
        {
            filter = new FileTypeOrFolderFilter(fileType);
            File currentFolder = new File(fromPath);
            File outputFolder = new File(outputPath);
            scanFolder(fileType, currentFolder, outputFolder);
        }
    
        private void scanFolder(final String fileType, File currentFolder, File outputFolder)
        {
            System.out.println("Scanning folder [" + currentFolder + "]...");
            File[] files = currentFolder.listFiles(filter);
            for (File file : files) {
                if (file.isDirectory()) {
                    scanFolder(fileType, file, outputFolder);
                } else {
                    copy(file, outputFolder);
                }
            }
        }
    
        private void copy(File file, File outputFolder)
        {
            try {
                System.out.println("\tCopying [" + file + "] to folder [" + outputFolder + "]...");
                InputStream input = new FileInputStream(file);
                OutputStream out = new FileOutputStream(new File(outputFolder + File.separator + file.getName()));
                byte data[] = new byte[input.available()];
                input.read(data);
                out.write(data);
                out.flush();
                out.close();
                input.close();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    
        private final class FileTypeOrFolderFilter implements FileFilter
        {
            private final String fileType;
    
            private FileTypeOrFolderFilter(String fileType)
            {
                this.fileType = fileType;
            }
    
            public boolean accept(File pathname)
            {
                return pathname.getName().endsWith("." + fileType) || pathname.isDirectory();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now I know how to copy files from one directory to another, this is
I need to move a file from one directory to another in the android
I want to copy some file from one folder to another folder of my
I am writing an ASP file to copy file from one folder to another:
Anybody know of a way to copy a file from path A to path
Does anyone know of an easy way to copy a database from one computer
I would like to know if it is possible to copy/move files to a
I am trying to copy a file from a child directory of my root
I am copying file from one location to another location in sdcard. now at
Alright I have a gigantic list of files I would like to copy from

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.