Article View: borland.public.jbuilder.java.api
Article #998Re: OutOfMemoryError
From: Alan Shiers
Date: Wed, 03 Jul 2002 16:38
Date: Wed, 03 Jul 2002 16:38
76 lines
3964 bytes
3964 bytes
Hi there,
I do use a function that takes a Win32 string, parses it and replaces
single backslash characters with double backslashes. So that's not the
problem.
I've somewhat solved this "Bad file descriptor" temporarily at least.
You see I was splitting the procedure in two. I would create the File
object and the FileInputStream object in a procedure called uploadFile()
in one class, and within it, call a worker thread that finished the job
where in its run() method would execute the while loop. The worker
thread gets a reference to the FileInputStream object and the
DataOutputStream object.
For some reason, when I split things up this way it generates this "Bad
file descriptor" error. I still don't know why that is.
Anyway, for the sake of expediency, I've cut out the use of the worker
thread for now and have placed all the code in the uploadFile() method.
Now, I don't get the "Bad file descriptor" error.
However, now I'm faced with a new dilemma. The while loop is working at
both ends except that the condition never exits the loop. I have an
endless loop condition. I've tried:
while((n = FileIn.read(buffer)) >= 0)
and
while((n = FileIn.read(buffer)) != -1)
Both are endless.
Any suggestions?
Alan
Owen Green wrote:
>
> "Alan Shiers" <ashiers@hfx.eastlink.ca> wrote in message
> news:3D226288.1C7C905@hfx.eastlink.ca...
> > Hi guys,
> >
> > I've been busy trying to implement the new code and I'm having a problem
> > with the conditional statement of the while loop.
> >
> > myFile = new File("C:\somepath\somefile");
> > if(myFile.exists())System.out.println("file exists");
> > FileIn = new FileInputStream(myFile);
> >
> > byte[] buffer = new byte[128];
> > int n;
> > while((n = FileIn.read(buffer)) >= 0) << Problem line
> > {
> > rq.output.write(buffer);
> > }
> >
> > The FileIn object is a FileInputStream object and everytime at runtime I
> > get an IOException stating that it has a "Bad file descriptor". I don't
> > understand what it is telling me or how to fix it.
> >
> > Earlier, I had created a File object using an absolute file path and
> > file name. Even tested it with the File.exists() method, which returned
> > true, and used the File object as an arguement for the FileInputStream
> > object, like so: FileIn = new FileInputStream(myFile);
>
> Isn't that exactly what you've shown above?
>
> > What is causing this "Bad file descriptor" thing?
>
> I'm not sure :) It could be
> a) That it doesn't understand what you're asking it; are you really writing
> win32 paths as "c:\blah\blah" as oppossed to "c:\\blah\\blah" or
> "c:/blah/blah"?
> b) There are a limited number of FD's available, afaik, do you have lots
> open at any one time? (this includes sockets, btw).
Technical Details
Message-ID:
<3D232898.CDB35265@hfx.eastlink.ca>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!supernews.com!wn2feed!wn3feed!worldnet.att.net!208.49.253.98!newsfeed.news2me.com!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnewsReferences:
<3D20CC5D.B70473C9@hfx.eastlink.ca> <MPG.178acb912dba8f7998b79d@newsgroups.borland.com> <3D21C1CA.F2D953E2@hfx.eastlink.ca> <3d21bb44_1@dnews> <3D21EC78.228A5CD3@hfx.eastlink.ca> <3d21e07b_2@dnews> <3D226288.1C7C905@hfx.eastlink.ca> <3d22ec28_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,28eab50e784856ac X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2002-07-03 08:40:32 PST Message-ID: <3D232898.CDB35265@hfx.eastlink.ca> Date: Wed, 03 Jul 2002 12:38:48 -0400 From: Alan Shiers <ashiers@hfx.eastlink.ca> Organization: Mustard Seed Software X-Mailer: Mozilla 4.78 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.api Subject: Re: OutOfMemoryError References: <3D20CC5D.B70473C9@hfx.eastlink.ca> <MPG.178acb912dba8f7998b79d@newsgroups.borland.com> <3D21C1CA.F2D953E2@hfx.eastlink.ca> <3d21bb44_1@dnews> <3D21EC78.228A5CD3@hfx.eastlink.ca> <3d21e07b_2@dnews> <3D226288.1C7C905@hfx.eastlink.ca> <3d22ec28_1@dnews> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.222.101.2 X-Trace: dnews 1025710566 24.222.101.2 (3 Jul 2002 08:36:06 -0700) Lines: 76 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!supernews.com!wn2feed!wn3feed!worldnet.att.net!208.49.253.98!newsfeed.news2me.com!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews