Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Process cannot access file

3 views
Skip to first unread message

Nick Collier

unread,
Feb 20, 2001, 10:21:51 AM2/20/01
to
Hi,

I'm getting the following error in an application (jdk 1.2 on NT).

java.io.FileNotFoundException: C:\repast\Models\Geopol\GeoData.txt (The
process cannot access the file because
it is being used by another process)
at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:100)
at java.io.FileWriter.<init>(FileWriter.java:52)
at uchicago.src.sim.analysis.SimData.writeToFile(SimData.java:233)

The confusing thing here is that no other process is accessing the file.
I'm using a BufferedWriter to write to the file. This writer appends new
data to the file periodically. However, the writer may be created by
different threads, but the threads are created consecutively. That is, a
thread is created, that thread writes to the file, and then terminates,
a new thread is created then writes to the file, then terminates.

I'm wondering if doing a BufferedWriter.flush() or
BufferedWriter.close() returns immediately and then writes in the
background, so that the file is still being written to when then next
thread tries to write to the file. I had thought though that java file
i/o didn't work this way though.

Other than this speculation, I can't think why this error occurs. Any
suggestions?

thanks,

Nick

--
Nick Collier
Social Science Research Computing
University of Chicago
http://repast.sourceforge.net

Ulrich Hofstoetter

unread,
Feb 26, 2001, 7:24:30 AM2/26/01
to
Nick Collier wrote:
>
> Hi,
>
> I'm getting the following error in an application (jdk 1.2 on NT).
>
> java.io.FileNotFoundException: C:\repast\Models\Geopol\GeoData.txt (The
> process cannot access the file because
> it is being used by another process)
> at java.io.FileOutputStream.openAppend(Native Method)
> at java.io.FileOutputStream.<init>(FileOutputStream.java:100)
> at java.io.FileWriter.<init>(FileWriter.java:52)
> at uchicago.src.sim.analysis.SimData.writeToFile(SimData.java:233)
>
> The confusing thing here is that no other process is accessing the file.
> I'm using a BufferedWriter to write to the file. This writer appends new
> data to the file periodically. However, the writer may be created by
> different threads, but the threads are created consecutively. That is, a
> thread is created, that thread writes to the file, and then terminates,
> a new thread is created then writes to the file, then terminates.
>

Make sure, that the writing thread closes the file correctly.


--
Dipl.-Inf. Ulrich Hofstötter
Visual Analysis AG
Neumarkter Str. 87
D - 81673 München

Tel: (+49)89-431981-38
Fax: (+49)89-431981-1
e-mail: ulrich.ho...@visualanalysis.com
www: http://www.visualanalysis.com

0 new messages