eben80
eben80

Reputation: 83

Overcoming in use file issue in Java

I have an issue with the following piece of java code running in Lotus Domino.

File filData = new File(domSapFilePath + "\\DOMSAP" + sdfDateTime.format((Calendar.getInstance()).getTime()) + ".csv");
        FileOutputStream foData = new FileOutputStream(filData);

        foData.write(DomSapGenerator.GenerateDomSapFile(con, dateFrom, dateTo).getBytes());

        foData.close();

        con.close();

The created file is in a UNC path but when it tries to write the file, it errors out saying that the file is in use by another process as can be seen below:

error message: java.io.FileNotFoundException: \\10.XX.XX.XX\xxxxxx\XXX\DOXXXXXX22230.csv (The process cannot access the file because it is being used by another process)

I've never programmed in Java before and I was hoping someone could point me in the right direction for a solution for this problem which is happening intermittently.

Thank you.

Upvotes: 0

Views: 411

Answers (3)

Simon O'Doherty
Simon O'Doherty

Reputation: 9359

You didn't say what operating system, but I am going to take a guess at windows based on the UNC format.

Microsoft have a program called Process Monitor. You can use this to track what is touching the file.

http://technet.microsoft.com/en-us/sysinternals/bb896645

But I would also go with leyrers response first.

Upvotes: 0

leyrer
leyrer

Reputation: 1492

As you are trying to open a UNC path, another cause for this error message could be that the code is running inside a scheduled agent.

In that case, the connection to the server \10.XX.XX.XX\ would be opened in the context of the OS account, that Domino is running under - usually "SYSTEM". As the "SYSTEM" user is not allowed to make a network connection to another server, the open call will fail.

Solution: Run the Domino service as another (AD) user that has the right to make network connections.

Upvotes: 1

Stephen C
Stephen C

Reputation: 719239

The most likely cause of this problem is that something else has the file open and is using it. The operating system is preventing you writing to the file because that could interfere with whatever it is that the "something else" is doing.

It is presumably happening intermittently because the "something else" is only using the file occasionally.

The solution is to figure out:

  • what is using the file,
  • why it is locking it, and
  • how to coordinate the different activities on the file to avoid the conflict.

Upvotes: 2

Related Questions