When I export the program to a executive Jar, file.txt does not import. The file.txt is in my src folder. Everything works file when i run the program in eclipse but when i export it, it does not import. HELP, I am new to Java and everything.

define "import"?
your .jar file is supposed to contain your .class file (and, if you want, your code and stuff like images) but an input file to use and handle shouldn't really be in there anyway.

When I export the program to a executive Jar, file.txt does not import. The file.txt is in my src folder. Everything works file when i run the program in eclipse but when i export it, it does not import. HELP, I am new to Java and everything.

because it is now packaged in your jar which can be verified by simply renaming extension to .zip and checking its contents the file can no longer be accessed normally when exexuting from within a jar archive. if the file is there you will have to extract it from your jar resource at runtime check this link here:http://stackoverflow.com/questions/5957589/load-resource-from-jar-file-at-runtime and here:http://www.velocityreviews.com/forums/t134544-load-images-and-text-file-from-jar-file.html

If you want to package other R/O files in your jar file you will have to use the getResource methods to read the file. You should be able to put any input file into your jar file.

Here is the code. can someone do the ger referance thing??? im comfused

BufferedReader br = new BufferedReader(
	   	          new InputStreamReader(new FileInputStream("src/timezones.txt")));

	   	                     				
	   			h = 0;					
	   				
	            StreamTokenizer tstream = new StreamTokenizer(br);
	   		         tstream.parseNumbers();
	   		         tstream.nextToken();
	   		     
	   		         while (tstream.ttype != StreamTokenizer.TT_EOF) {
	   		      
	   		             a[h] = (int) tstream.nval;   
	   		             tstream.nextToken();
	   		            
	   		             city[h] = (String) tstream.sval;
	   		             tstream.nextToken();
	   		            
	   		             b[h] = (int) tstream.nval;
	   		             tstream.nextToken();
	   		                   
	   		                  
	   		             h++;
	   		         }

Here is the code. can someone do the ger referance thing??? im comfused

BufferedReader br = new BufferedReader(
	   	          new InputStreamReader(new FileInputStream("src/timezones.txt")));

	   	                     				
	   			h = 0;					
	   				
	            StreamTokenizer tstream = new StreamTokenizer(br);
	   		         tstream.parseNumbers();
	   		         tstream.nextToken();
	   		     
	   		         while (tstream.ttype != StreamTokenizer.TT_EOF) {
	   		      
	   		             a[h] = (int) tstream.nval;   
	   		             tstream.nextToken();
	   		            
	   		             city[h] = (String) tstream.sval;
	   		             tstream.nextToken();
	   		            
	   		             b[h] = (int) tstream.nval;
	   		             tstream.nextToken();
	   		                   
	   		                  
	   		             h++;
	   		         }

we are not here to code for you. The links i gave especially the second one should be enough to get you started

tried google? if not, take a look at this. You're bound to find enough links to help you on your way.

tried google? if not, take a look at this. You're bound to find enough links to help you on your way.

very funny... :(

it's not ment as a joke.
every single person on this forum is a volunteer. this means we're helping you on our own time. just a bit of courtesy from your side (and the forum rules) dictate you have to do some effort for yourself.

NormR1 gave you everything you need to to complete the job, but instead of realy trying, you're just asking us for the code. we will gladly help you improve your code, correct your bugs and all that, but we won't write it for you.

it's not ment as a joke.
every single person on this forum is a volunteer. this means we're helping you on our own time. just a bit of courtesy from your side (and the forum rules) dictate you have to do some effort for yourself.

NormR1 gave you everything you need to to complete the job, but instead of realy trying, you're just asking us for the code. we will gladly help you improve your code, correct your bugs and all that, but we won't write it for you.

lol so u think that i have not tried all the suggestions..


seeing i am absolutely new to this, what NormR1 gave me was a little something like this:

me : how do u fly
NormR1 : use a plane
me : well here is the plane i made, its not working can u fix it
you : i think that NormR1 gave u enough info, we cant make a plane for you

no offense to NormR1. But anyways guys thanxs a lot for your input, once i figure out a way to make the plane i will let you know.

lol so u think that i have not tried all the suggestions..


seeing i am absolutely new to this, what NormR1 gave me was a little something like this:

me : how do u fly
NormR1 : use a plane
me : well here is the plane i made, its not working can u fix it
you : i think that NormR1 gave u enough info, we cant make a plane for you

no offense to NormR1. But anyways guys thanxs a lot for your input, once i figure out a way to make the plane i will let you know.

from the links i gave :

/*As the documentation says, the Class.getResource method will prepend the
"package path" to resource names that do not begin with a slash. In your
case, if file is placed as images/myfile.jpg in your jar-file you
probably want to call it with .getResource("/images/myfile.jpg").*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;

public class JavaApplication32 {

    public static void main(String[] args) {
        URL url = new JavaApplication32().getClass().getResource("/images/myfile.jpg");//JavaApplication32 is the name of the main class
        InputStreamReader ins = null;
        try {
            ins = new InputStreamReader(url.openStream());
        } catch (IOException ex) {
            Logger.getLogger(JavaApplication32.class.getName()).log(Level.SEVERE, null, ex);
        }
        BufferedReader br = new BufferedReader(ins);

    }

and looking at your code:

BufferedReader br = new BufferedReader(
	   	            new InputStreamReader(new FileInputStream("src/timezones.txt")));
                           ....
	                   StreamTokenizer tstream = new StreamTokenizer(br);
                           ....

I see no reason why you couldnt attempt it

if you 're seriously as 'new to Java' as you claim you are, you should be trying easier stuff.

you see, in your words, NormR1 said: use a plane
your (future) employer, would say: do it and fast, if not, you 're fired.

no one here is trying to hold you back, or patronize you, we're just trying to help you in such a way that would not only benefice you in the short run, but that would help you in the long run as well.

from the links i gave basically copy and pasted:

/*As the documentation says, the Class.getResource method will prepend the
"package path" to resource names that do not begin with a slash. In your
case, if file is placed as images/myfile.jpg in your jar-file you
probably want to call it with .getResource("/images/myfile.jpg").*/
URL url = this.getClass().getResource("/images/myfile.jpg");
ins = new InputStreamReader(url.openStream());
bufferedReader = new BufferedReader( ins );

thanx bud, i tried that, but the the program did not compile.. but i just figured out what *this* is sopposed to be. so it works now.
i put this InputStream ins = main.class.getResourceAsStream( "timezones.txt" );

but what is the URL sopposed to do btw?

the program did not compile.

When you get errors, you should post them here if you want help with them.

what is the URL sopposed to do

It tells the user where something is located: Universal Resource Locator

if you 're seriously as 'new to Java' as you claim you are, you should be trying easier stuff.

you see, in your words, NormR1 said: use a plane
your (future) employer, would say: do it and fast, if not, you 're fired.

no one here is trying to hold you back, or patronize you, we're just trying to help you in such a way that would not only benefice you in the short run, but that would help you in the long run as well.

thanks, i know where you are comming from, but i did try it if that is what you mean, I just needed to see how the two codes connected togeather *correctly*.. lol .. but ye thanx for helping me .. i really appreciated it..

thanx bud, i tried that, but the the program did not compile.. but i just figured out what *this* is sopposed to be. so it works now.
i put this InputStream ins = main.class.getResourceAsStream( "timezones.txt" );

but what is the URL sopposed to do btw?

see my edited post above. and the url is the path to which you have imported the file into your jar archive. go to the archive and extract its contents there should be minimum 2 directories. now navigate through and find the file. if you cant it hasnt been added to your jar library then. the path you find it at is the url you use

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.