jQuery in Action, 2nd edition*
The moose likes I/O and Streams and the fly likes Directory, File, Jar input problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Directory, File, Jar input problem" Watch "Directory, File, Jar input problem" New topic

Directory, File, Jar input problem

Ronnie Coh

Joined: Mar 08, 2004
Posts: 13
I've written a program that reads files from vaious locations on my drive to populate JComboboxes. It works file when I run the program through an IDE, but when I Jar the Classes it will not work.

Here is an example:

cboCrop = new JComboBox();
String line = null;
BufferedReader br =
new BufferedReader(
new BufferedReader(new FileReader("C:\\Test\\Data\\Jclimate.txt"));
while ((line = br.readLine()) != null)
cboCrop.addItem(line.substring(3, 3 +12));

Any suggestions will be appreciated. Thanks...Ronnie
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

'will not work' isn't precise enough.

Is there a general 'catch (Exception e)' clause, which is silent as the grave of the dead programmer ({})?

Ronnie Cohen

Joined: Mar 08, 2004
Posts: 3
The problem is that it will not find the file when I run the program in my JAR.

Joe Ess

Joined: Oct 29, 2001
Posts: 8836

So you are getting a ClassNotFound exception?
In order to find a class file within a jar, either the classpath has to contain the jar file:

Or you create an executable jar and run it with the -jar flag:

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Ronnie Coh

Joined: Mar 08, 2004
Posts: 13
No, ClassNotFond Exceptions. The program just hungup. I managed to get it to work by putting the Data and Text files outside the Jar in the same foldre as the jar.

Not the Jar will not finded the two Jars that war included in the jar. I uded a Manifest file file:

Main-Class: folder.program
Class-Path: folder.jarone.jar folder.jartwo.jar

But it will not find the two jars. Any ideas? Thanks
I agree. Here's the link: http://aspose.com/file-tools
subject: Directory, File, Jar input problem
Similar Threads
Problem reading a file
Using DOS commands in Java
Working with file and directories..
how to finish the process forcibly?
What is the representation of the empty line?