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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:01:02+00:00 2026-05-24T18:01:02+00:00

I have a java code for copy file from one folder to another folder.

  • 0

I have a java code for copy file from one folder to another folder. I used the following code (I used Windows 7 operating system),

CopyingFolder.java

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;


public class CopyingFolder {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        File infile=new File("C:\\Users\\FSSD\\Desktop\\My Test");
        File opfile=new File("C:\\Users\\FSSD\\Desktop\\OutPut");
        try {
            copyFile(infile,opfile);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    private static void copyFile(File sourceFile, File destFile)
            throws IOException {
    if (!sourceFile.exists()) {
            return;
    }
    if (!destFile.exists()) {
            destFile.createNewFile();
    }
    FileChannel source = null;
    FileChannel destination = null;
    source = new FileInputStream(sourceFile).getChannel();
    destination = new FileOutputStream(destFile).getChannel();
    if (destination != null && source != null) {
            destination.transferFrom(source, 0, source.size());
    }
    if (source != null) {
            source.close();
    }
    if (destination != null) {
            destination.close();
    }

}

}

While I’m using the above code I got the following Error. Why it will arise? how can I resolved it?

java.io.FileNotFoundException: C:\Users\FSSD\Desktop\My Test (Access is denied)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:106)
    at CopyingFolder.copyFile(CopyingFolder.java:34)
    at CopyingFolder.main(CopyingFolder.java:18)
  • 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-24T18:01:04+00:00Added an answer on May 24, 2026 at 6:01 pm

    Access Denied has to do with User Account Control. Basically, you’re trying to read a file which you don’t have permission to read (see the file permission under File properties).

    You can see if the file is readable by doing File.canRead() method.

    if (infile.canRead()) {
        //We can read from it.
    
    }
    

    To set it to readable, use the File.setReadable(true) method.

    if (!infile.canRead()) {
       infile.setReadable(true);
    }
    

    Alternatively you can use java.io.FilePermission to provide file read permission.

    FilePermission permission = new FilePermission("C:\\Users\\FSSD\\Desktop\\My Test", "read");
    

    Or

    FilePermission permission = new FilePermission("C:\\Users\\FSSD\\Desktop\\My Test", FilePermission.READ);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have to write the code using simple java.i have to copy one source
I want to copy one file from system1 to system2. both these system are
I have the code to copy a file to another location. public static void
I have the following Java 6 code: Query q = em.createNativeQuery( select T.* +
I just played with Java file system API, and came down with the following
I am trying to read a single file from a java.util.zip.ZipInputStream , and copy
I have some Java code that uses curly braces in two ways // Curly
I have this java code: <script src=http://www.google.com/jsapi></script> <script type=text/javascript> google.load(jquery, 1.2.6); $(a#more).click(function() { $(#info_box).show(blind,
I have some Java code which performs bitwise operations on a BitSet. I have
I have this Java code, and I want to do the same thing in

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.