Reading a text-file from within a Jar-file...

I've made a program, that reads from a text-file. And it works great. But when I try to put the program into a jarfile, I get a fileNotFoundException... I have the textfile both inside and outside the jarfile... with the same result.
Does anyone know what I might be doing wrong?
Thanx in advance!
Martin

Depends on the path you enter for the text file. If you simply put "filename.txt" then you should try to have the file in the same directory as the class which accesses the file.
Cheers,
H�vard

Similar Messages

  • Runtime.exe() is not working from within a jar file.

    Hi All,
    I have a jar file which have classes and a package in it.
    One of these classes is calling another class which is present in the package.
    The code i am using it is as follows:
    Runtime r=Runtime.getRuntime();
    Process p=null;
    p=r.exec("java deep.slideshow.PlayShow");It is working fine when i am executing it without making jar file.
    But when i make a jar file of all these things , this exec() is not working.
    I have tried a lot.
    If any body has any idea suggest me.
    Thanks

    thanks a lot for your reply friend.
    I tried the same you tell me to do by using the cmd;
    java -cp my.jar package.class  And then tried to make the jar file with the help of eclipse,
    after adding my jar file into classpath of my project in eclipse.
    Its working fine on my local system.
    But when i put this jar file on some other system it does not call my jar file(obviously bcz it will not the find the jar file according to the classpath set on my local system. )
    Is there any way that i can keep this jar into my project and then can give the classpath dynamically
    so that it can pick the file from my project automatically.?
    Later on i will pack this whole thing into a full jar file and it will work on a single click.
    Is it possible or not ?
    Please suggest me.
    Thanks

  • Unable to display the Content of a data file from within another data file in Oracle webcenter portal.

    We have a Content Presenter taskflow. This task flow is added to a jspx page. The taskflow fetches the content from the contributor data file. The contributor data file is having a WYSIWYG editor. The content of the WYSIWYG editor is being displayed correctly through the task flow.
    We have some links in the WYSIWYG editor. These links again point to some data files. When we click on these links from within the portal, then we are getting a blank page(the url of this blank page is: http://localhost:7101/eWSIBPortal/faces/oracle/webcenter/sitestructure/render.jspx?datasource=UCM%23dDocName%3AWSIB_ARTICLE) and not displaying the content of the data file that we are pointing to from the WYSIWYG editor.
    We want to display the content of these data files(which we have pointed from WYSIWYG editor) in-line within the portal.
    Please help us to resolve this issue and let us know if any information is required from our end.

    Thanks for reply. However, can I use XSQL to dump the formated text to a file? or just can display to client through web browsers?

  • Safari (Snow Leopard) will not link to website (pdf) files from within other pdf files

    Meeting agendas (in pdf format) have 'web links' to other pdf files, but Safari says not enough info in the webaddress.  But it works O.K. in Windows Explorer.

    Open browser preferences
    ex Safari>Preferences>Extentions   and un-enable any ext that mabe interferring , ex divX
    or open Help> installed Plug-ins and remove Adobe Acrobat.
    if still a problem
    Quit Safari.
    In the Finder, select Go ▹ Go to Folder from the menu bar, copy the text on the line below into the box that opens, and press return:
    ~/Library/Preferences/com.apple.Safari.plist
    A Finder window will open with an item selected. Move the selected item to the Desktop, leaving the window open.
    Launch Safari and test. Its settings will have reverted to what they were they first time you launched it. If it works as expected, recreate the settings and delete the item you moved to the Desktop. Otherwise, quit Safari again and put the file you moved back where it was, overwriting the newer one created in its place.

  • Can't get file from resource in jar.

    hi,
    I'm using the folowing mechanism to get a configuration file from my classes jar file.
    URL configUrl = Config.class.getResource("/resources/"+fileName);
    File ressourceFile = new File(configUrl.toURI());while this is working perfectly when i run my app in stand-alone it fails in JavaWebStart. it gives me the folowing error :
    java.lang.IllegalArgumentException: URI is not hierarchical
         at java.io.File.<init>(Unknown Source)
         at line 2 aboveafter some investigation it seems that the first line doesn't return a valid URL. I'm getting something like :
    jar:file:C:/Documents%20and%20Settings/Patrice/Application%20Data/Sun/Java/Deployment/cache/javaws/http/Dfiona/P80/RMface2face.jar!/resources/system.propertiesthe problem (I think) lies in the URL protocol : jar:file:C:/...
    when I run the same lines in stand-alone I get :
    file:/E:/Project/.../classes/resources/system.propertieswhich is just what I want.
    Is there something I am doing wrong?
    thanx,
    Patrice.

    ok thanx.
    in the end I copy the file locally with :
    try{
        InputStream input = Config.class.getResourceAsStream("/resources/"+fileName);
        OutputStream output = new FileOutputStream(userConfigFile);
        byte[] temp = new byte[128];
        while(input.available()>0){
            int nb = input.read(temp);
            output.write(temp,0,nb);
        input.close();
        output.close();
    } catch (IOException e){
    }it works perfectly.
    thx.

  • Possible to create a JAR file from within a java app?

    Is it possible to create a jar file from within a java application?
    Can it be done more elegantly than by spawning-off another
    process with the Runtime and exec() portions of the api?
    Thanks
    Scott

    Thanks! I was mislead by the API notes for java.util.jar:
    The JarOutputStream class is used to write the contents
    of a JAR file to any output stream.
    I was looking for a class or method to make jar files.
    Seems this is it ;)
    Thanks
    Scott

  • How to get the entries in a jar/zip file contained within a jar/zip file?

    If I want to list the jar/zip entries in a jar/zip file contained within a jar/zip file how can I do that?
    In order to get to the entry enumeration I need a Zip/JarFile:
    ZipFile zip = new ZipFile("C:/java_dev/Java_dl/java_jdk_commander_v36d.zip");
    // Process the zip file. Close it when the block is exited.
    try {
    // Loop through the zip entries and print the name of each one.
    for (Enumeration list =zip.entries(); list.hasMoreElements(); ) {
    ZipEntry entry = (ZipEntry) list.nextElement();
    System.out.println(entry.getName());
    finally {
    zip.close();
    Zip file "java_jdk_commander_v36d.zip" contains two zip entries:
    1) UsersGuide.zip
    2) JDKcommander.exe
    How to list the entries in "jar:file:/C:/java_dev/Java_dl/java_jdk_commander_v36d.zip!/UsersGuide.zip"?
    The following code:
    URL url = new URL("jar:file:/C:/java_dev/Java_dl/java_jdk_commander_v36d.zip!/UsersGuide.zip");
    JarURLConnection jarConnection = (JarURLConnection)url.openConnection();
    zipFile = (ZipFile)jarConnection.getJarFile();
    would point to "jar:file:/C:/java_dev/Java_dl/java_jdk_commander_v36d.zip", which is no help at all and Class JarURLConnection does not have an enumeration method.
    How can I do this?
    Thanks.
    Andre

    I'm not sure I understand the problem. The difference between a zip and jar file is the manifest file; JarFile is extended from ZipFile and is able to read the manifest, other than that they are the same. Your code
    for (Enumeration list =zip.entries(); list.hasMoreElements(); ) {
    ZipEntry entry = (ZipEntry) list.nextElement();
    System.out.println(entry.getName());
    }is close to what I've use for a jar, below. Why not use the same approach? I don't understand what you're trying to do by using JarURLConnection - it's usually used to read the jar contents.
    String jarName = "";
    JarFile jar = null;
    try
        jar = new JarFile(jarName);
    catch (IOException ex)
        System.out.println("Unable to open jarfile" + jarName);
        ex.printStackTrace();
    for ( Enumeration en = jar.entries() ;  en.hasMoreElements() ;)
        System.out.println(en.nextElement());
    }

  • Unable to open CS3 Files from within the application

    Good Afternoon
    I work as IT Support for company looking after 10 ADOBE Creative Suite 3 end-users.
    One of my colleagues is unable to open Illustrator or Photoshop files from within their respective applications, but she is able to open them from outside ok.
    I have reinstalled ADOBE CS3 and this appeared to resolve the issue, only for it to return again a day later.
    She has no other applications or processes running during her attempt to open a file from within CS3.
    She will click on Open and the 'Open File' window will flash up for a split second, then the whole application will be frozen. It is as if the 'Open File' window is there, but isnt there because we cant click on it, but the application thinks it is displaying and so she can not click on anything else. The only way to close the application is to end the process under Task Manager.
    While I am sitting here tearing what little amount of hair I have on my head, can anyone point me in the right direction?
    Is this a Windows problem or an ADOBE problem do you think?
    I look forward to any replies.
    Thank you

    Hi Bob
    Ok...
    Opened illustrator but was unable to open the 'Open File' window.
    Changed the screen resolution, it suddenly worked!
    Changed the screen resolution back to as it was before, it also worked.
    What could cause this do you think?
    By simply changing the screen resolution and back again, the 'Open File' window displayed itself.
    Very bizarre!

  • Timecapsule - opening files from within an application!!

    I have a time capsule... 500Mb
    I have an airport extreme with external hard drive - 250 Mb.
    Through Finder, I can place files on either of these drives and open them from Finder.
    If I open Numbers, or Pages, then try to open any file on Timecapsule, it appears that there are no files
    If I open Number, or Pages, then try to open any file on the Airport Extreme external disk - it works!
    Simple question really.... why cannot I see or open any file from within an application that resides on Timecapsule?? It's driving me crazy!!!
    Message was edited by: GrahamDurkin

    File dialogs have the ability to "group" items, which prohibits you from changing sort options.  The group icon looks like six little squares.  Click on it and instead of grouping by date, group by "none" and then you can change sort orders.

  • How do I create a series of text frames from a list of files?

    And I'm back again.
    This time, I'm wondering how I can use JavaScript to place a series of text frames from a list of files, preferably with the ability to specify criteria before running the script.
    Here's the details: I work for a newspaper and I lay out stories for the pages (in addition to the other part of my job, laying out ad spaces, as detailed in a previous thread, for which I requested another script, thanks Andreas and Jongware ). The file names for the stories are labeled for the section they go in, like L- for Life, C- for Comment, S- for Sports, etc.
    I'd like to create a script that asks for a criteria in a text box (where I can type L-, C-, S- or whatever else I need) and then places all of the stories, in a specified directory, whose file names match what was typed in the box, one text frame for each.
    I can't rightly tell if this is a simpler or more difficult script to write out, but I plan on putting research into it as usual so I can develop it myself. However, I figured it would be more efficient to ask first, then research, so that while I'm researching, I can refer to the opinions of my fellow forumites, and/or the mods.
    Thanks again for any assistance offered.

    And I'm back again.
    This time, I'm wondering how I can use JavaScript to place a series of text frames from a list of files, preferably with the ability to specify criteria before running the script.
    Here's the details: I work for a newspaper and I lay out stories for the pages (in addition to the other part of my job, laying out ad spaces, as detailed in a previous thread, for which I requested another script, thanks Andreas and Jongware ). The file names for the stories are labeled for the section they go in, like L- for Life, C- for Comment, S- for Sports, etc.
    I'd like to create a script that asks for a criteria in a text box (where I can type L-, C-, S- or whatever else I need) and then places all of the stories, in a specified directory, whose file names match what was typed in the box, one text frame for each.
    I can't rightly tell if this is a simpler or more difficult script to write out, but I plan on putting research into it as usual so I can develop it myself. However, I figured it would be more efficient to ask first, then research, so that while I'm researching, I can refer to the opinions of my fellow forumites, and/or the mods.
    Thanks again for any assistance offered.

  • Unable to open files from within Photoshop

    Hi, I've updated to CC 2014.2.1 and I'm continuing to get this message when I attempt to open a file from within Photoshop (it started when I installed a beta versionYosemite, so I switched back to Mavericks, but it didn't help, [so many updates with Cloud, I lose track..]).  I noticed someone else with a similar problem, but from 2013. Anyway, I get this message: 'Could not complete your request because of a program error.'  I restart Photoshop, then I can open a few files, but then the errors start over.
    Also, I'm not really familiar with the 'forum' means of support, but if anyone knows a solution to this beyond 'google it', which I've done, I'd appreciate it.
    -Stu

    Thanks Jeffery Tranberry—this did the trick. BUT while an answer to my issue gave the following feedback to Adobe....
    Use of COVERFLOW if EXTREMELY IMPORTANT (in Photoshop) when working fast with hundreds of images. Who the heck labels every single image asset file—and knows what that is without a visual cue? WHEN IS THIS ON THE ROADMAP TO BE FIXED?????????? UGH! MAVERICKS has been coming for MONTHS. Why was this not vetted on Adobe's end as a valuable roadmap item for its users? I would have ranked this a high item from a user experience end and fought for inclusion on the developers roadmap. What is the ETA on a real fix concerning Mavericks & Coverflow use with Photoshop?

  • How to run a batch file from within an Oracle 9i Form?

    Hi, I would like to execute a batch file from within an oracle form - I'm assuming there's some PLSQL command I can use? I am not allowed to use any third party libraries, and I'm hoping I can get away without having to progam any C or Java to do it. I don't want to run my java program from my form, but my lecturer is insisting on it.
    Can anyone help?
    Thanx
    Adam

    Can u give me an example
    I need to run a batch files that does a series of step doing dir ( in 3 different folders)
    after each one it shows on screen with a pause & user press enter
    can this work out ?

  • Changing a .properties file from within a programme

    Hi, I was just wondering is there anyway that i can change a .properties file from within a programme?
    I have certain values in the .properties file and I want to add a username and password to the file once it has been entered in a login part of the programme.
    I have had a look at the docs and can not seem to find any suitable methods.
    Cheers Gareth.

    store is a good method.
    In practical use, sometimes you have a .properties file full of comments (properties files are to be modified by humans, and humans need comments), but they are not retrieved by "load" so they will not be stored back by "store". It's a pity that it happens (the equivalent Windows API, WritePrivateProfileString, has a better behaviour).
    Maybe someone has written a method that can modify a properties file, without changing the order of the pairs name=value and without throwing out comments.

  • Retrieving Jar path in the HD from within the jar?

    I have a small problem. I wrote a program which is packed in a jar file and this program is able to compile and run java files (Which I do by running javac and java processes) but the kind of files that this program compiles requires some other libraries inside the same package (In the jar file) so I am wondering how can I retrieve the jar path in the harddisk from within this jar because at the moment I ask the user where the program is and I think it is kind of ugly to ask the user where the program is from within the exact same program we are looking for.
    Hope I made myself understandable.
    Best Regards
    NooK

    Thanks for the answer. I mistakenlly ended writing a new thread (New to the forum)
    but if you would kindly look here, I have other problem now which I have been working on for a whole day.
    http://forum.java.sun.com/thread.jsp?thread=524717&forum=31&message=2514471
    Best Regards
    NooK

  • Opening Files from within an application

    OSX 10.8.2 - Column view - When I open a file from within Acrobat (9.5.4) the list of files is sorted chronologically (Today, Yesterday, Previous 7 Days etc.) Is there a way to turn this off. This started when I upgraded to OSZ 10.8.

    File dialogs have the ability to "group" items, which prohibits you from changing sort options.  The group icon looks like six little squares.  Click on it and instead of grouping by date, group by "none" and then you can change sort orders.

Maybe you are looking for

  • Convert a movie from Quicktime to MPEG4 in MPEG Streamclip

    I want to convert a movie from Quicktime (.mov) which I created in Final Cut Express to MPEG4 in MPEG Streamclip to be able to see it on my Samsung TV. The problem is that the uncompressed movie, comverted only from Quicktome to MPEG 4, stops almost

  • .Mac messages do not apear in Mail

    When I recieve any number of messages on my .Mac mailaccount the Mail Icon in the dock shows that number of messages to indicate that new mail has arrived. However, when I open the Mail window (and press get mail) there apear no new messages in the i

  • Userid/password in a popup dialog box?

    When I sign on to the forums today either on an iPhone or Firefox in windows, I'm getting a popup box to enter userid/password instead of the usual Oracle single sign on page. Is this something new?

  • Need to move documents from Record center to file share

    I am trying to figure out how can I manage moving the documents from record center to file share. I want to move the older documents that are taking lot of space from record center in to some kind of file share. There are thousands of old documents t

  • Starcraft2 crashing on loading

    im running bim32-wine-sc2 and after i click play it does nothing for a little bit then crashes. wine cd/Installer.exe fixme:ntdll:NtPowerInformation semi-stub: SystemPowerCapabilities fixme:font:CreateScalableFontResourceW (0,L"C:\\users\\lnxusr\\Tem