dcow
dcow

Reputation: 7985

Java opens file successfully when run in Eclipse but not in Netbeans

I have been working on a project in Eclipse that requires me to open a file. It's working as expected. I imported my project into Netbeans just to check it out but when run, the file can't be opened. I think a screenshot would be most helpful in this case:

screenshot of the problem in Netbeans

Any idea what the issue is? I've even explicitly specified the run directory in the project properties and that still doesn't work.

Additional Info:

Also, as suggested by a few users, I added in my catch block:

System.err.println(new File(inFileName).getAbsolutePath();

Which, as it should, returns:

C:\Users\David\Dev\projects\Autocuration\pearltrees_export_02-07-2012.rdf

Upvotes: 2

Views: 345

Answers (3)

dcow
dcow

Reputation: 7985

After attempting to construct the URI manually,

System.out.println(new File(System.getProperty("user.dir")).toURI().resolve(inFileName));

I got the following exception:

Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in path at index 32: pearltrees_export_02-07-2012.rdf

Considering there is no 32nd character, I assume the printStackTrace method must trim the string obtained from the exception message before printing.

Whatever the case, it appears that Netbeans parses Run arguments using the ' ' (space) character as a separator. However, it also includes that space when it passes the arguments to the main method. In other words, I was trying to open:

"pearltrees_export_02-07-2012.rdf "

rather than:

"pearltrees_export_02-07-2012.rdf"

Simply trimming argument fixes the problem:

inStream = new FileInputStream(new File(inFileName.trim()));

Anyway, I cannot find any documentation stating this is the intended behavior as it is certainly different from how the java binary behaves (and any other editors I know of). For this reason I consider this a bug, and I submitted a bug report:

http://netbeans.org/bugzilla/show_bug.cgi?id=215429

I guess we'll see what the Netbeans fellows have to say..

Upvotes: 1

Benoit
Benoit

Reputation: 1993

In the catch block you should add this:

System.err.println(new File(inFileName).getAbsolutePath());

Upvotes: 0

lcguida
lcguida

Reputation: 3847

Is the same OS? Same file name? Acording to the message given, it looks like there's some problem in the file name.

Upvotes: 0

Related Questions