Java program hangs on new PrintWriter

O

Oz Levanon

Hi.
I have a java program running on linux (Redhat 9, Java 1.4.2, build
1.4.2-b28).
The program periodically accesses a file on the hard disk using the
following code:

FileOutputStream fos = new FileOutputStream(filename);
PrintWriter pw = new PrintWriter(fos);
// ...
// writes stuff to the file.
// ...
pw.close();
fos.close();


Every now and then (sometimes after hundreds of times, sometimes after
less) the program hands. I can see from debug prints I've added that
it is stuck after the new FileOutputStream(filename) and before the
new PrintWriter(fos);
The program doesn't exit (and no throwable is thrown) but rather stays
up and running, but never gets past this line.
Does anyone have any idea what could cause a program to hang in this
line? Can anything on linux be done to a file that will cause a
program trying to access it hang?

TIA, oz.
 
H

hiwa

Hi.
I have a java program running on linux (Redhat 9, Java 1.4.2, build
1.4.2-b28).
The program periodically accesses a file on the hard disk using the
following code:

FileOutputStream fos = new FileOutputStream(filename);
PrintWriter pw = new PrintWriter(fos);
// ...
// writes stuff to the file.
// ...
pw.close();
fos.close();


Every now and then (sometimes after hundreds of times, sometimes after
less) the program hands. I can see from debug prints I've added that
it is stuck after the new FileOutputStream(filename) and before the
new PrintWriter(fos);
The program doesn't exit (and no throwable is thrown) but rather stays
up and running, but never gets past this line.
Does anyone have any idea what could cause a program to hang in this
line? Can anything on linux be done to a file that will cause a
program trying to access it hang?

TIA, oz.
Try:

Code:
try{
PrintWriter out = new PrintWriter(new BufferedWriter(new
FileWriter("your-output-file")));
//... do output
out.close();
}
catch(Exception e){
e.printStackTrace();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top