Text Files in .Jar file

Alright, I have my program packaged up in a .jar file. I have figured out how to access images that are in the .jar
ImageIcon nextImage=new ImageIcon(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("next.png"))); That works well.
Now, When the program loads, I would like it to load some initial values from a .txt file that is in the .jar. How do i do that? Is this a situation where I have to use an inputStream? If so.... I need an example. I'm relativly new and I am learning as I go.
I was previously loading these values using a BufferedReader and a FileReader, but that was before I decided i wanted all the files in the Jar.
Txt file name: fields.txt
jar. Taxi.jar
Thanks a ton in advance.

Yes, most likely you need an InputStream. Here's how to use the Java API documentation to help find a solution.
You already know how to read a file containing an image by using ClassLoader.getSystemResource(). So, look at the API documentation for getSystemResource(). What does it return? It returns a URL. Ok, now what methods are available in the URL class that might help read a text file? Search the documentation for URL to find your answer.

Similar Messages

  • Getting error FF with my extension: cant find the file at jar:file in omni.jar!/chrome/browser/content/browser/ some junk text

    After installing my plugins to ff4 and ff5 I am getting error File not found.
    Firefox can't find the file at jar:file:///Applications/Firefox.app/Contents/MacOS/omni.jar!/chrome/browser/content/browser/%E6%A5%A6%E6%95%AC%E2%BC%BA%E2%BC%AF%E7%8D%95%E7%89%A5%E2%BD%B3%E6%B5%A1%E6%B1%AF%E4%B0%AF%E6%89%A9%E6%85%B2%E7%A5%B2%E4%84%AF%E7%81%B0%E6%A5%AC%E6%85%A3%E6%A5%B4%E6%B9%AF%E3%88%A5%E5%8C%B0%E7%81%B5%E6%BD%B0%E7%91%B2%E4%84%AF%E6%BD%A4%E6%95%A2%E4%8C%AF%E6%B9%AF%E7%89%B4%E6%89%A9%E7%91%B5%E2%95%A5%E3%80%B2%E5%8D%83%E2%B8%B5%E2%BC%B1%E6%BD%83%E6%99%AE%E6%9D%A9%E7%89%B5%E7%91%A1%E6%BD%A9%E2%BD%AE%E4%89%89%E5%91%85%E6%B5%A5%E2%BD%B0%E6%BD%83%E7%91%AE%E6%A5%B2%E7%95%A2%E6%95%B4%E3%84%B6%E3%9C%B8%E3%90%B4%E2%B8%B3%E6%89%A9e%E3%90%B4%E2%B8%B3%E6%89%A9e%08%01%EC%92%B0%E0%B0%BE%EC%92%B8%E0%B0%BE%EC%92%BC%E0%B0%BE%EF%BF%BF%EC%93%80%E0%B0%BE.

    Try:
    "Reset all user preferences to Firefox defaults" on the [[Safe mode]] start window.
    * http://kb.mozillazine.org/Resetting_preferences
    Delete the files extensions.* (extensions.sqlite, extensions.rdf, extensions.cache, extensions.ini) and compatibility.ini in the Firefox [[Profiles|profile folder]] to reset the extensions registry.<br />
    New files will be created when required.
    See "Corrupt extension files":
    * http://kb.mozillazine.org/Unable_to_install_themes_or_extensions
    If you see disabled, not compatible, extensions in "Tools > Add-ons > Extensions" then click the Tools button at the left side of the Search Bar (or click the "Find Updates" button in older Firefox versions) to do a compatibility check or see if there is an update.
    Create a new profile as a test to check if your current profile is causing the problems.
    See:
    * [https://support.mozilla.com/kb/Basic+Troubleshooting#w_8-make-a-new-profile Basic Troubleshooting: Make a new profile]
    If that new profile works then you can transfer some files from the old profile to that new profile (be careful not to copy corrupted files)
    See:
    * http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox

  • Trying to access the java script files via jar file in WEB SERVER

    hi all,
    I am trying to access the java script files via jar file ,which is present in Apache webserver in order to minimise the number of hits to app server.some thing like cache ...
    in jsp the code goes like this...
         <script type="text/javascript"  archive="http://localhost:14000/dojo.jar!" src="dojo.jar/parser.js" " ></script>{code}
    But i am not able to access the js file which is put in jar file present in the  webserver.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Hi,
    You can use DWR (Direct Web remoting) for that. It is easy AJAX for java. ou can directly call the java script function from java class and also java class from javaScripts..
    Regards,
    Hardik

  • How to list files from .jar file in applet?

    I have created applet and export all files to .jar file.
    I use File.list() method in applet to list files from one directory and that works ok but if I try to do that from web browser it sends exception AccessDenied meaning that File.list() isn't allowed in browser.
    I know what's the problem but I don't know how to solve it.
    What I want is to read from directory list of files.
    Help anyone?

    I will post here my code so that can be seen what I want to do:
    import java.awt.BorderLayout;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.URLClassLoader;
    import java.nio.charset.Charset;
    import javax.swing.JApplet;
    import javax.swing.JPanel;
    import javax.swing.JTextPane;
    public class test extends JApplet {
         private static final long serialVersionUID = 1L;
         private JPanel jContentPane = null;
         private JTextPane jTextPane = null;
          * This is the xxx default constructor
         public test() {
              super();
          * This method initializes this
          * @return void
         public void init() {
              this.setSize(449, 317);
              this.setContentPane(getJContentPane());
          * This method initializes jContentPane
          * @return javax.swing.JPanel
         private JPanel getJContentPane() {
              if (jContentPane == null) {
                   jContentPane = new JPanel();
                   jContentPane.setLayout(new BorderLayout());
                   jContentPane.add(getJTextPane(), BorderLayout.CENTER);
              return jContentPane;
          * This method initializes jTextPane     
          * @return javax.swing.JTextPane     
         private JTextPane getJTextPane() {
              if (jTextPane == null) {
                   jTextPane = new JTextPane();
              return jTextPane;
         public void start(){
              File fileDir= new File("somedirectory");
              String strFiles[]= fileDir.list();
              String a="";
              for(int i =0;i<strFiles.length;i++){
                   a=a+strFiles;
              this.jTextPane.setText(a);
    Method init() is irelevant, it just adds JTextPane in applet.
    Method start() is relevant, it runs normaly when started from Eclipse but from browser it sends exception AccessDenied.

  • How to get the class file of jar file

    hello all,
    is there any way to get the class file of jar file,as we have when we compile a java file we get class file
    same do we have any option to get the class file of jar file

    A jar file is a zip archive, so you can uznip it or extract the contents with the command "jar" - if it is what you need.

  • Since downloading firefoz 4, everytime I make a browser search I get a second page with :"Firefox can't find the file at jar:file://how can I solve the problem. Kindly reply to :ramses1@videotron.ca

    Question
    firefox 4, when I make a browser search I get a second page:"Firefox can't find the file at jar:file:///D:/Program Files/Mozilla Firefox/omni.jar!/chrome/browser/content/browser/<url></url>", how can I solve the problem.

    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Appearance/Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]

  • I upgraded to Firefox 8. Now my home page says this: "Firefox can't find the file at jar:file:///C:/Program Files (x86)/Mozilla Firefox/omni.jar!/browserconfig.properties.

    This is what it says on my screen when I open Firefox:
    Firefox can't find the file at jar:file:///C:/Program Files (x86)/Mozilla Firefox/omni.jar!/browserconfig.properties.

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • When searching, I get this message: Firefox can't find the file at jar:file:///C:/Program Files (x86)/Mozilla Firefox/omni.jar!/chrome/en-US/locale/browser-region/region.propertiesproblems.

    when I enter a word in the search window (the one with the curved arrow at the end), I get this message:
    Firefox can't find the file at jar:file:///C:/Program Files (x86)/Mozilla Firefox/omni.jar!/chrome/en-US/locale/browser-region/region.propertiesproblems.

    Try the Firefox SafeMode to see how it works there. <br />
    ''A troubleshooting mode, which disables most Add-ons.'' <br />
    ''(If you're not using it, switch to the Default Theme.)''
    * You can open the Firefox 4/5/6/7 SafeMode by holding the '''Shft''' key when you use the Firefox desktop or Start menu shortcut.
    * Or use the Help menu item, click on '''Restart with Add-ons Disabled...''' while Firefox is running. <br />
    ''Don't select anything right now, just use "Continue in SafeMode."''
    ''To exit the Firefox Safe Mode, just close Firefox and wait a few seconds before using the Firefox shortcut (without the Shft key) to open it again.''
    If it is good in the Firefox SafeMode, your problem is probably caused by an extension, and you need to figure out which one. <br />
    http://support.mozilla.com/en-US/kb/troubleshooting+extensions+and+themes

  • How to run .class file and .jar file in jdev9i

    I want to run .class file and .jar file in jdev9i,what should I do?
    Also,I want to generate .class file and .jar file in jdev9i,what should i do?

    Add the .class file containing the public static void main(...) method to the project by clicking on the + toolbar button in the navigator, open the project properties and properly set the additional classpath then right click on the .class in the navigator and say run. It should work, I've just tried it.
    Doesn't work for a .jar yet, in JDeveloper 9.0.3 it works both for .class and .jar
    Michel

  • Text file within jar file

    Can anybody tell me if it's possible to read and write to a text file stored within the .jar file package? I can maintain a constant file length if that enables me to read and write.
    cheers,
    Steve

    reading a text from, from a jar file..... if the jar is in your classpath you can call
    getClass().getResourceAsStream ( "/myServerConfig.properties" );Note the "/", which stops the file from being interpreted as a class name, see Class.getResourceAsStream()
    writing... nothing as easy as the reading solution above.
    You'd probably have to actually "update" the JAR file contents with a new version of the text file.
    regards,
    Owen

  • How to use txt files in jar file

    Hi all
    I just made a program that uses a text file, but I havent managed to work it correctly, program runs without jar correctly, but when I packaged all files into a jar, it couldnt find txt file, so I can only run it when I create another text file outside of jar.
    How can I solve this??

    I used this:
    Scanner fileScan = new Scanner (new file
    ("Words.txt"));
    but when I make a jar file, it doesnt find the txt
    file inside a jar,
    do I need to specify path or something?I have already told you that you shouldn't use new File(..) you should use getResourceAsStream(String name) to get an InputStream to the file.
    Kaj

  • Help adding new files to Jar file.

    I am new to Java and am having problems haveing our Web App work after I have recreated the JAR file...this is what I did...
    Changed to the following directory at a dos prompt:
    D:\jdk1.3.1_01\bin
    Ran the following to extract the files from the jar file.
    jar xvf app2.jar
    ...this created 5 directories with various files.
    copied new and updated graphic files to
    D:\jdk1.3.1_01\bin\app2\images
    Recreated the jar file using the following command (pv com javavp meta-inf borland are the 5 directories that were extracted from the original jar file above):
    jar.exe cvf app2.jar pv com app2 meta-inf borland
    I now have a new jar file that is a similar size, so it looks good, but when I put it in our web site, it does not recognize certain frames (that get information from the database) that it did before (the frames are blank)
    Any thoughts on what I am doing wrong?
    Also, are there any Windows programs that i can use to make this easier instead of using the dos commands?
    Thanks...

    To change the contents while inside a java program, you might be able to use Runtime.exec(String[]). Make the array with "jar.exe" as the first index, flags in the second, and remaining arguments in the remaining indecies.

  • Deleting file from .jar file

    I m having trouble with the Forum search, so sorry if this question has been answered before in this forum.
    If I create a .jar (or an .ear) file, then open the file using Winzip and then delete a file from the zip, does it corrupt the .jar file? I ran into such a problem recently where I could not deploy the application because the .ear file still contained references to the deleted file.

    No, Winzip doesn't corrupt jar files. But if you have something else that expects to find X in the jar file and you deleted X, it isn't surprising that problems arise.

  • Firefox won't open, error message"can't find file at jar:file" etc.

    "Firefox cannot find file@jar:file:///program files/Mozilla Firefox/omni jar!/browser config. properties." I tried to download firefox and refreshed the desktop link and still no go. Cannot get firefox to browse.

    Se also:
    *http://kb.mozillazine.org/Preferences_not_saved
    *https://support.mozilla.org/kb/Preferences+are+not+saved
    Create a new profile as a test to check if your current profile is causing the problems.
    See "Basic Troubleshooting: Make a new profile":
    *https://support.mozilla.org/kb/Basic+Troubleshooting#w_8-make-a-new-profile
    There may be extensions and plugins installed by default in a new profile, so check that in "Tools > Add-ons > Extensions & Plugins" in case there are still problems.
    If that new profile works then you can transfer some files from the old profile to that new profile, but be careful not to copy corrupted files.
    See:
    *http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox

  • How to use files in Jar file

    Hi,
    I have one program which displays images on main form.
    But when I package all these classes and image files it shows file not found.
    I want it should read the image files which are in the same jar file.
    How can I use the files which are packaged in a Jar file?

    Here's some sample code I stole from another website.
    public void readTextFromJar(String s) {
    String thisLine;
    try {
    InputStream is = getClass().getResourceAsStream(s);
    BufferedReader br = new BufferedReader
    (new InputStreamReader(is));
    while ((thisLine = br.readLine()) != null) { 
    System.out.println(thisLine);
    catch (Exception e) {
    e.printStackTrace();
    }

Maybe you are looking for

  • NEWBIE JSP QUES

    I'm really new at jsp, and have a frustratingly simple question. All I'm trying to do is get a .jsp page to display in internet explorer. So I create the file and put this in it: <% String test = "this is a test"; %> <html> <%=test%> </html> And noth

  • Timeline playhead goes back to beginning when it hits end

    Is there a preference or something somewhere I need to turn off to prevent the playhead in the timeline from going back to the beginning of the timeline and start playing again from the beginning, after it plays through the entire timeline once and i

  • Cannot load JDBC driver class 'com.microsoft.jdbc.sqlserver.SQLServerDriver

    Hi, i am doing a forum application. i am trying to connect database connection through javax.sql.DataSource. I am using Eclipse editor for developing this application and i am using sql server 2000 database. i have create a servlet file. here is the

  • Database files

    Can i transfer some address files from an excel doc to contacts? or can i download a free or inexpensive database for mac similar to excel or filemaker ? i have just transferred from an old iMac to newish MacBook pro (M Lion) and nothing works! All m

  • ACR6.7 download for CS5

    I have downloaded ACR6.7 but do not know how to get it into CSR5/Bridge. Any help would be appreciated.