0

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.

eben80
  • 83
  • 2
  • 7
  • 1
    Did you consider the possibility that indeed it is used by another process? You are writing to a network file, what steps did you take to ensure nobody else on your intranet is working with that file? – Marko Topolnik Apr 23 '12 at 10:53

3 Answers3

2

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.
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
1

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.

leyrer
  • 1,444
  • 7
  • 9
  • Thank you all for your answers. I think it might be the backup of the iSeries Partition that this share exists of that is conflicting with the file creation. I suppose I wanted to know if there is a way of java locking the file after it creates it so that the backup process cannot lock it. – eben80 May 04 '12 at 09:43
0

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.

Simon O'Doherty
  • 9,259
  • 3
  • 26
  • 54