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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:38:46+00:00 2026-06-05T16:38:46+00:00

I have a function that copies binary file public static void copyFile(String Src, String

  • 0

I have a function that copies binary file

    public static void copyFile(String Src, String Dst) throws FileNotFoundException, IOException {
    File f1 = new File(Src);
    File f2 = new File(Dst);
    FileInputStream in = new FileInputStream(f1);

    FileOutputStream out = new FileOutputStream(f2);

    byte[] buf = new byte[1024];
    int len;
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();
    out.close();
}

and the second function

    private String copyDriverToSafeLocation(String driverPath) {
    String safeDir = System.getProperty("user.home");
    String safeLocation = safeDir + "\\my_pkcs11tmp.dll";
    try {
        Utils.copyFile(driverPath, safeLocation);
        return safeLocation;
    } catch (Exception ex) {
        System.out.println("Exception occured while copying driver: " + ex);
        return null;
    }
}

The second function is run for every driver found in the system.
The driver file is copied and I am trying to initialize PKCS11 with that driver.
If initialization failed I go to next driver, I copy it to the tmp location and so on.

The initialization is in try/catch block
After the first failure I am no longer able to copy next driver to the standard location.

I get the exception

Exception occured while copying driver: java.io.FileNotFoundException: C:\Users\Norbert\my_pkcs11tmp.dll (The process cannot access the file because it is being used by another process)

How can I avoid the exception and safely copy the driver file?

For those curious why am I trying to copy the driver … PKCS11 has nasty BUG, which prevents using drivers stored in the location that has “(” in the path … and this is a case I am facing.

I will appreciate your help.

  • 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-05T16:38:48+00:00Added an answer on June 5, 2026 at 4:38 pm

    If the file is used by an other process and locked, there is no generic solutions to be able to access it. You best chance is to use FileLock but it’s plateform-dependant, read the documentation, it’s written that the results are “advisory”, so be carefull. you can also take a look at the ReentrantReadWriteLock class.

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

Sidebar

Related Questions

I have the function below that copies a file in a directory and recreate
I have a function that sets a vector to a string, copies a Sweave
In my Java code I have function that gets file from the client in
I have a function that is supposed to read from a file into a
Say I have function X in file A, and I wanted to move that
imagine you have a function that creates/copies/moves files. [logic] For the case that a
I am trying to write a function that copies a string parameter to the
I am building a server app that copies files using System.IO.File.Copy(...) function. My files
I have a function that copies values from a table1 to a table2. The
I have a function running on document load that copies the contents of a

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.