An exception is thrown when I open some files in linux, however, this doesn't occurrs when I do the same in windows XP
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ariel_Romero
Posted On:   Monday, November 10, 2008 07:49 PM

Hi every body: An exception is thrown when I open some files in linux, this doesn't occurrs when I do the same in windows XP. This is the pierce of code that throws the exception: [CODE] 42 public static byte[] readFileBytes(File file) throws IOException { 43 java.io.InputStream istr = new java.io.FileInputStream(file); 44 byte bytes[] = new byte[istr.available()]; 45 istr.read(bytes); 46 istr.close(); 47 return bytes; 48 } [/CODE] I received this exception: Exception in thread "main" java.io.IOException: No such file or directory at java.io.FileInputStream.readBytes(Native Method) at java.io.FileInputStream.read(   More>>

Hi every body:

An exception is thrown when I open some files in linux, this doesn't occurrs when I do the same in windows XP.
This is the pierce of code that throws the exception:
[CODE]
42 public static byte[] readFileBytes(File file) throws IOException {
43 java.io.InputStream istr = new java.io.FileInputStream(file);
44 byte bytes[] = new byte[istr.available()];
45 istr.read(bytes);
46 istr.close();
47 return bytes;
48 }
[/CODE]

I received this exception:
Exception in thread "main" java.io.IOException: No such file or directory
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:177)
at ca.co.coding.Main.readFileBytes(Main.java:45)

In windows I used the same file and the code is executed succesfully.
Could somebody tell me why is this happening ???
Thanks in advance

   <<Less

Re: An exception is thrown when I open some files in linux, however, this doesn't occurrs when I do the same in windows XP

Posted By:   Robert_Lybarger  
Posted On:   Tuesday, November 11, 2008 10:24 PM

No, I doubt anyone can tell you why it's happening. However, you should add some diagnostics to the code. Check
file==null, file.exists(), file.isDirectory(), and file.canRead(). Print out the values to see if they match up with your expectations.
About | Sitemap | Contact