Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > One File Found, the other Not Found ?!?!?!

Reply
Thread Tools

One File Found, the other Not Found ?!?!?!

 
 
mcampo84@gmail.com
Guest
Posts: n/a
 
      08-07-2006
I am using NetBeans (5.0) to write an applet that requires reading from
an input file - for now let's call it "testInput.txt". In order to
read from the file I use a BufferedReader with the following code:

FileReader inputFile = new
FileReader(String.valueOf(cl.getResource(
"data/testInput.txt")));
BufferedReader in = new BufferedReader(inputFile);

I created a "data" subfolder in the "src" folder that NetBeans provides
and that's where testInput.txt resides (NetBeans bundles everything in
this folder into the jar when it compiles). When I run the program,
however, I get the following error:

java.io.FileNotFoundException:
<pathName>.<jarName>.jar!\testInput.txt
(The filename, directory name, or volume label syntax is
incorrect).

What is confusing me is that earlier in the same program, I read from
another file in the same directory - "testInput.xml" - and use the same
code as above, with "testInput.xml" replacing "testInput.txt".

Can anyone help me figure this one out?

 
Reply With Quote
 
 
 
 
mcampo84@gmail.com
Guest
Posts: n/a
 
      08-07-2006
Oh, btw - I forgot to mention that "cl" is a ClassLoader.

-mc

 
Reply With Quote
 
 
 
 
Roland de Ruiter
Guest
Posts: n/a
 
      08-07-2006
On 7-8-2006 23:14, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I am using NetBeans (5.0) to write an applet that requires reading from
> an input file - for now let's call it "testInput.txt". In order to
> read from the file I use a BufferedReader with the following code:
>
> FileReader inputFile = new
> FileReader(String.valueOf(cl.getResource(
> "data/testInput.txt")));
> BufferedReader in = new BufferedReader(inputFile);
>
> I created a "data" subfolder in the "src" folder that NetBeans provides
> and that's where testInput.txt resides (NetBeans bundles everything in
> this folder into the jar when it compiles). When I run the program,
> however, I get the following error:
>
> java.io.FileNotFoundException:
> <pathName>.<jarName>.jar!\testInput.txt
> (The filename, directory name, or volume label syntax is
> incorrect).
>
> What is confusing me is that earlier in the same program, I read from
> another file in the same directory - "testInput.xml" - and use the same
> code as above, with "testInput.xml" replacing "testInput.txt".
>
> Can anyone help me figure this one out?
>

FileReader is capable of reading a resource (i.e. a file) from the
filesystem, not from a resource in a jar file.

Try the following instead:

// Assuming cl instanceof ClassLoader
final String resourceName = "data/testInput.txt";
final String resourceEncoding = "ISO-8859-1";
// or: = "UTF-8";
// or: = System.getProperty("file.encoding");
// It should match encoding of data/testInput.txt
InputStreamReader inputReader = new
InputStreamReader(cl.getResourceAsStream(resourceN ame),
resourceEncoding);
BufferedReader in = new BufferedReader(inputReader);
--
Regards,

Roland
 
Reply With Quote
 
mcampo84@gmail.com
Guest
Posts: n/a
 
      08-07-2006
Thanks, Roland. It worked like a charm!

-mc

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Found and Not Found Don Phillipson Wireless Networking 1 10-02-2009 12:24 AM
Re: Module not found in script that was found in command-lineinterpreter. Possible Path issue? Jacob Davis Python 0 04-15-2008 07:28 PM
Re: Module not found in script that was found incommand-line interpreter. Possible Path issue? Trent Mick Python 0 04-03-2008 05:54 PM
Why does one regex routine work and not the other one? TtfnJohn Python 1 06-11-2007 07:17 AM
Namespace not found in aspx but IS found in code behind William Parker ASP .Net 1 06-27-2004 06:13 AM



Advertisments