Article View: borland.public.jbuilder.java.api
Article #290Too many open files error thrown from java.io.File
From: Scott
Date: Sat, 03 Apr 2004 15:45
Date: Sat, 03 Apr 2004 15:45
88 lines
3316 bytes
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;
}
Technical Details
Message-ID:
<406edc6e$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,606a3d8ee4cf8a04,start X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2004-04-03 08:10:19 PST Reply-To: "Scott" <scotthpowell@yahoo.com> From: "Scott" <scotthpowell@yahoo.com> Newsgroups: borland.public.jbuilder.java.api Subject: Too many open files error thrown from java.io.File Date: Sat, 3 Apr 2004 10:45:37 -0500 Lines: 90 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 24.239.150.17 Message-ID: <406edc6e$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1081007214 24.239.150.17 (3 Apr 2004 07:46:54 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail