🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.api
1 messages
1 total messages Started by Scott Sat, 03 Apr 2004 15:45
Too many open files error thrown from java.io.File
#290
Author: Scott
Date: Sat, 03 Apr 2004 15:45
88 lines
3316 bytes
Hi,

I'm using an MP3 class library from http://www.vdheide.de/projects.html.  It
is the same library in the J-Jukebox project.

The library offers a set of classes to read MP3 files.  The main class is
MP3File, which extends File.

I've got code that scans all of my MP3 and looks for those that have ID3
tags (the older way to mark the artist, song title, etc. in the MP3 file).
The code appears below.

I've got about 1800 files to scan.  At file # 897, I get a
java.io.IOException: Too many open files.

Can anyone suggest how to avoid this problem (aside from only handling 897
files at a time)?  If there was a File.close() command, I'd happily execute
it.

I've been writing Java for less than a week, so forgive any obviously bad
choices I've made below.  And accordingly any advice is really appreciated.

Thank you

public HashSet getID3Files (File directory) throws ID3v2WrongCRCException,
ID3v2DecompressionException, ID3v2IllegalVersionException, IOException,
NoMP3FrameException{

File[] files = directory.listFiles();

/* I'm using a HashSet so I can compare it against a set of files that have
ID3v2 tags.  If there's a better way, I'm happy to do it */

HashSet id3s = new HashSet();


/* Now let's loop over the collection and see what we get */

for (int x = 0; x < files.length; x++ ){

try {

System.out.println ("Looking for file # " + x + files[x].getPath());

/* Is this the right way, to create new MP3File each time? */

MP3File mp3 = new MP3File (files[x].getPath());

/* Is this the right way, to create new ID3 each time? */

if (new ID3(mp3).checkForTag())

/* I'm adding that mp3 object to the hash set.  I don't need to, if say this
whole problem goes away by returning an array of filenames.  But want I'm
really wondering is why you can't say File.close() [MP3File extends File] */

{ id3s.add(mp3);

System.out.println (mp3.getName() + " is by " +
mp3.getArtist().getTextContent());

}

else

{ System.err.println (files[x].getPath() + " has no tag.");}

}catch (java.io.IOException e) {

System.err.println("Error on file " + files[x] + " message is " +
e.getMessage() + " for error type " + e.toString());

return id3s;

}catch (Exception e){

System.err.println("Error on file " + files[x] + " message is " +
e.getMessage() + " for error type " + e.toString());

}

}


return id3s;


}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads