This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Directory, File, Jar input problem" Watch "Directory, File, Jar input problem" New topic
Author

Directory, File, Jar input problem

Ronnie Coh
Greenhorn

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 ({})?


http://home.arcor.de/hirnstrom/bewerbung
Ronnie Cohen
Greenhorn

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

Thanks.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8839
    
    7

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
Greenhorn

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?