• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem reading file: Bad file descriptor

 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you locating the file on the filesystem?
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Turned out to be a premature close() call on RandomAccessFile.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}



reply
    Bookmark Topic Watch Topic
  • New Topic