Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FileNotFoundException

1 view
Skip to first unread message

HardCase

unread,
Jun 25, 2002, 11:42:03 AM6/25/02
to
FileInputStream in = new FileInputStream(temp);
int capacity = in.available();
byte[] array = new byte[capacity];
in.read(array);
in.close();
FileOutputStream out = new FileOutputStream(temp2);
if(temp.canWrite()){
out.write(array);
} else {
throw new IOException(temp2.getAbsolutePath()+" kan niet beschreven
worden.");
}
out.close();

This code causes a runtime error:
Exception in thread "main" java.io.FileNotFoundException: E:\ABN\ABN.EXE
(Het sy
steem kan het opgegeven pad niet vinden)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:102)
at java.io.FileOutputStream.<init>(FileOutputStream.java:62)
at java.io.FileOutputStream.<init>(FileOutputStream.java:132)
at WriteThread.writeBackUp(WriteThread.java:158)
at test.main(WriteThread.java:173)
In english: The system can't find the given path. Why does this error
occures here?

Thanks in advance
--
PENTIUM = Produces Erroneous Numbers Thru Incorrect Understanding of
Math
* MSN dhert...@hotmail.com ICQ 157482585
* http://www.sphosting.com/dietmar

Jon Skeet

unread,
Jun 25, 2002, 12:52:25 PM6/25/02
to
HardCase <dher...@tiscali.be> wrote:
> FileInputStream in = new FileInputStream(temp);
> int capacity = in.available();
> byte[] array = new byte[capacity];
> in.read(array);

Never use this code. available() is almost always dodgy, and there's no
guarantee that the whole of the file will be read in one go. See IOUtil
in my library at http://www.pobox.com/~skeet/java/skeetutil for a better
way to read the whole of a stream into a byte array.

> in.close();
> FileOutputStream out = new FileOutputStream(temp2);
> if(temp.canWrite()){

Don't you mean if temp2.canWrite()? Note that the error condition will
never occur, as if you can't write the previous line will have thrown an
exception anyway.

> In english: The system can't find the given path. Why does this error
> occures here?

My guess is that the directory doesn't exist.

--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

0 new messages