aspose file tools*
The moose likes Tomcat and the fly likes Problem reading file: Bad file descriptor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Problem reading file: Bad file descriptor" Watch "Problem reading file: Bad file descriptor" New topic
Author

Problem reading file: Bad file descriptor

Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342
Hi,

I have a servlet running under Tomcat 5.0.28 which reads data from a large binary file on disk. Problem is I am seeing a java.io.IOException: Bad file descriptor when I try to use RandomAccessFile.read() call.



I'm at a bti of a loss on this one. A stand alone app which does the same thing on the same PC reading from the same data file accesses it no problem. I'd be grateful of any suggestions, especially from anyone who has seen this error before under Tomcat. I have experienced something similar before but I cannot remember how it was resolved

cheers,
Ben


SCJP 1.4, www.gsi3d.org.uk
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

How are you locating the file on the filesystem?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342
The file locations are being read from a database table, some are in the form:

E:\aDirectory\aFile.dat

Others are network paths like:

\\networkStore\\aDirectory\\aFile.dat

Neither seem to work, although they do work when used with a stand-alone app.
Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342
Turned out to be a premature close() call on RandomAccessFile.
John Te
Greenhorn

Joined: Jun 07, 2010
Posts: 1
Hi,

I also run the same problem today.

Platform : MAC OS with Java 1.6, Tomcat 6.x --

Purpose: Try to create a new file and write new file content inside Tomcat servlet.

Exception in Tomcat:


java.io.IOException: Bad file descriptor
at java.io.FileOutputStream.writeBytes(Native Method)
at java.io.FileOutputStream.write(FileOutputStream.java:260)
at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:202)
at sun.nio.cs.StreamEncoder.implClose(StreamEncoder.java:297)
at sun.nio.cs.StreamEncoder.close(StreamEncoder.java:130)
at java.io.OutputStreamWriter.close(OutputStreamWriter.java:216)
at java.io.BufferedWriter.close(BufferedWriter.java:248)


Code:
// write to the same file
File fh2 = null;
try {
fh = resource.getFile();
fh2 = new File(fh.getAbsolutePath() + ".new");
os = new FileOutputStream(fh2);
bw = new BufferedWriter(new OutputStreamWriter(os));
for (int i = 0; i < list.size(); i++) {
bw.write(list.get(i));
System.out.println(list.get(i));
}
} catch (Exception e) {
throw e;
} finally {
try {
if (os != null) {
os.close();
}



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem reading file: Bad file descriptor