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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:23:07+00:00 2026-06-16T05:23:07+00:00

I am trying to copy files from one folder to another using the FileUtils

  • 0

I am trying to copy files from one folder to another using the FileUtils method “static void copyDirectory(File srcDir, File destDir)” from apache commons io (2.4) with the following code:

String srcDir  = "/sourceDirectory/examples/";
String destDir = "/tmp/examples/";
try{
    FileUtils.copyDirectory(new File(srcDir), new File(destDir));
} catch (IOException e){
    e.printStackTrace();
}

The file structure looks like the following:

examples/                           (read access)
examples/.subdirectory              (NO access)
examples/file1.txt                  (read access)
examples/file2.txt                  (read access)
examples/subdirectory2/file1.txt    (read access)
examples/subdirectory2/file2.txt    (NO access)

The problem is, that in srcDir there are a few files and one subdirectory I don’t have access to. FileUtils.copyDirectory throws an “java.io.FileNotFoundException: .subdirectory (Permission denied)” and aborts.

Is it possible to ignore those files I don’t have permission to and just copy all the other files I can read?

  • 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-16T05:23:08+00:00Added an answer on June 16, 2026 at 5:23 am

    Using a FileFilter as follow:

    FileUtils.copyDirectory(new File(srcDir), new File(destDir), new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.canRead();
        }
    });
    

    See the javadoc for more information.

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

Sidebar

Related Questions

What I am trying to do is copy files from one folder to another.
I'm trying to copy files from one location to another using subprocess library and
Basically I'm trying to copy a file from one place to another but I
I am new to programming, trying to copy files from one location to another,
Using MongoDB I'm trying to copy a database from one server to another. My
I'm trying to copy all the files from one directory to another, removing all
I'm trying to copy an android db file from my application folder to another
I am trying to copy all format file (.txt,.pdf,.doc ...) file from source folder
I'm trying to copy a bunch of files with a specific extension from one
I am trying to create a program to copy all the files from one

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.