Retrieving .txt file from jar for an applet

I guess this is a newbie question but i checked the tutorial sessions and i am doing exactly what it says there but still...no luck:
I'm trying to access a .txt. file stored in the .jar file where my applet .class file is stored. I'm using:
String s = "myfile.txt";
// get current Class loader
ClassLoader cl = this.getClass().getClassLoader();
FileInputStream is = new FileInputStream((cl.getResource(s)).toString());
BufferedReader in = new BufferedReader(new InputStreamReader(is));But when the applet is viewer from the browser or from the appletviewer, i'm getting the FileNotFoundException:
java.io.FileNotFoundException: jar:file:\C:\FeatureSelection\sFeatureSelection.jar!\myfile.txt (The filename, directory name, or volume label syntax is incorrect)
I tried to use the following instead:
FileInputStream is = new FileInputStream((myApplet.class.getResource(s)).toString());orFileInputStream is = new FileInputStream((getClass().getResource(s)).toString());but the same exception is still there.
The jar file and the html file are all stored in this directory C:\FeatureSelection\
The signed jar file is called sFeatureSelection.jar
Any help would be greatly appreciated!
Thanks.

One way to get at files in a jar is to put the jar in the CLASSPATH and then just refer to the resource by its path in the jar. If the same path occurs in two different jars, then you only get the first one, based on the order of the jars in CLASSPATH, I think.
The classloader is involved, which can be confusing, but an easy way to try this is:
String s = "myfile.txt";
URL u = this.class.getClassLoader().getResource(s);
Object o = u.getContent();Now, you only really know that something matched that path and now it is in a URL.
I think the Object will be a stream and you have to read() it or something.
BTW: I encourage you to examine the URL, but it is not necessary to do so.
If you have somehitng like a GIF image, then here is an example of how to work with that:
http://www.devx.com/tips/Tip/5697
Here is a way to get the bytes without involved the ClassLoader:
http://www.javaworld.com/javaworld/javatips/jw-javatip49.html
Take your pick.

Similar Messages

  • Retrieving .txt file from JAR

    I guess this is a newbie question but i checked the tutorial sessions and i am doing exactly what it says there but still...no luck:
    I'm trying to access a .txt. file stored in the .jar file where my applet .class file is stored. I'm using:
    String s = "myfile.txt";
    // get current Class loader
    ClassLoader cl = this.getClass().getClassLoader();
    FileInputStream is = new FileInputStream((cl.getResource(s)).toString());
    BufferedReader in = new BufferedReader(new InputStreamReader(is));But when the applet is viewed from the browser or from the appletviewer, i'm getting the FileNotFoundException:
    java.io.FileNotFoundException: jar:file:\C:\FeatureSelection\sFeatureSelection.jar!\myfile.txt (The filename, directory name, or volume label syntax is incorrect)
    I tried to use the following instead:
    FileInputStream is = new FileInputStream((myApplet.class.getResource(s)).toString());orFileInputStream is = new FileInputStream((getClass().getResource(s)).toString());but the same exception is still there.
    The jar file and the html file are all stored in this directory C:\FeatureSelection\
    The signed jar file is called sFeatureSelection.jar
    Any help would be greatly appreciated!
    Thanks.

    Thanks for your help, but i'm still getting the same exception:
    java.io.FileNotFoundException: file:\c:\FeatureSelection\sFeatureSelection.jar!\myfile.txt (The filename, directory name, or volume label syntax is incorrect).
    As for the JarInputStream, i checked it out online, but i'm not too sure how i can use these methods to apply'em for my problem here. Does anyone have a sample code that uses JarInputStream?
    Thanks.

  • Need to copy .txt file from FTP server and downloaded on local server directory.

    I need to figure out a way to copy .txt file from ftp server in local server directory using sql jobs.

    Below links will help achieving it:
    https://www.virtualobjectives.com.au/sqlserver/ftp_scripts.htm
    http://www.mssqltips.com/sqlservertip/2884/sql-server-integration-services-ssis-ftp-task-for-data-exchange/

  • Help reading a .txt file from the hard drive....

    Hi guys,
    Ok... I need to know how to read a .txt file from the hard drive... I have an example on how to read from a disk, but I don't have a disk drive. I could be confusing terminology, but I don't think I am. Here is the code I have for reading from a disk.. please let me know how I should change it to read from a hard drive.
    Also, when the error pops up, it says that it can't read another .txt file that is not specified in the code... any ideas how that is occuring? Please advise.
    import java.io.*;
    public class TEST {
    public static void main(String args[]) throws Exception{
    FileReader fr = new FileReader("customer.txt");
    BufferedReader bfr = new BufferedReader (fr);
    String s;
    while ((s=bfr.readLine())!= null){
    System.out.println (s);
    fr.close();
    }

    Ok... I need to know how to read a .txt file from the
    hard drive... I have an example on how to read from a
    disk, but I don't have a disk drive. I could be
    confusing terminology, but I don't think I am. Here
    is the code I have for reading from a disk.. please
    let me know how I should change it to read from a
    hard drive.The code will be the same, regardless of where the file is located. It's just the filename that will be different.
    Also, when the error pops up, it says that it can't
    read another .txt file that is not specified in the
    code... any ideas how that is occuring? Please
    advise.Probably becuase the class file (compiled version of the source code) is a different version to the source code, i.e. the source code hasn't been recompiled since the source code was changed.
    How does this relate to EJBs?

  • How do I retrieve a file from Trash using Time Machine in Mavericks?

    Is it even possible to retrieve a file from Trash from a Time Machine backup? Does Time Machine even back up the Trash? I've been told a total restore from a Time Machine backup will put the past Trash back on the Mac, but what if I just want to restore an individual file?
    Shortly after emptying my Trash on my Mac (10.9.4) for the first time in weeks, I realized I needed one of the files I'd just erased. Trying to retrieve with Time Machine was not fruitful, however, because I couldn't find the file on any of the past backups using the normal Enter Time Machine interface. However, I know it would have been in the Trash during all of the most recent backups.
    So I researched how to find the backups of Trash with Time Machine, but I think all of the solutions I found on various online forums were pre-Mavericks and do not seem to work now. I've basically tried 2 things:
    Show Trash in Finder using the Terminal command: open ~/.Trash
    It shows the hidden Trash folder in Finder, located in Macintosh HD/Users/User. For easy access, I added the .Trash folder to the Finder Sidebar. But I can't get to it in the backups. The Trash shortcut in the Finder Sidebar is always grayed out in the old backups using the Time Machine app. And it does not show up in ~ when looking through the backups.backupdb folder on my external HD.
    I also tried the Terminal command to show all hidden files in Finder: defaults write com.apple.finder AppleShowAllFiles YES
    But while many hidden files do suddenly appear in Finder, curiously, the User's .Trash folder is not one. This is true for the Finder of the Mac, the backups.backupdb folder on the External HD, and Time Machine app.
    Thanks.

    How do I retrieve a file from my backup in Time Capsule?
    It depends on the type of file that you are trying to retreive.
    In general.....
    Open Time Machine by clicking on the clock icon on the dock
    Wait a few minutes for Time Machine to fully load
    Use the timeline at the far right of the window to go back in time to a date when the file was still on your Mac
    Click that date
    Navigate using the Finder interface to locate the file that you want
    Click on the file to highlight it
    Click Restore at the lower right of the window to be brought back to the present
    You have to retrieve other types of files differently. For details, see:
    http://pondini.org/TM/28.html

  • "Error retrieving xml file from database"

    Hello All,
    I have installed and configured planning with Shared services. While I try to create an instance in Configuration Utility by entering the Instance Name, Host Name, Port (8300) and Click "Next", I get this error -
    *"System failure:Error retrieving xml file from database".*
    My RDBMS is - SQL Server 2005
    OS - Windows 2003 Server
    I am unable to work on planning for few months due to this error.. I would sincerely appreciate if someone can provide me a solution for this..
    Thanks much,
    Varma.

    Hi,
    Ive seen this before.
    If this is a new environment could you create a blank database and configure it as your System database? Then try again and you should be fine.
    I think you may have some invalid entries in your sys database.
    Seb
    www.taysols.com.au

  • Product Instance Registration Error Message: "System Failure: Error while retrieving xml file from database"

    Hi Planning installation Gurus,
    Did u get any luck to resolve this problem as i am also facing same problem "Error creating instance" during install of Planning 9.3.1. i tried 30-50 times reconfiguration every time same problem..
    OS: Vista Premium
    SQL Server 2005
    Essbase:9.3.1
    Error Message: "System Failure: Error while retrieving xml file from database"
    Details of error:::::::::::::::::::::::::
    at com.hyperion.planning.event.HspSysExtChangeHandler.run(Unknown Source
    Can not get JDBC connection for SYS external changed actions.
    Can not get JDBC connection.
    java.lang.NullPointerException
    at com.hyperion.planning.sql.HspSQLImpl.getConnection(Unknown Source)
    at com.hyperion.planning.event.HspSysExtChangeHandler.actionPoller(Unkno
    wn Source)
    at com.hyperion.planning.event.HspSysExtChangeHandler.run(Unknown Source
    Can not get JDBC connection for SYS external changed actions.
    Can not get JDBC connection.
    java.lang.NullPointerException
    at com.hyperion.planning.sql.HspSQLImpl.getConnection(Unknown Source)
    at com.hyperion.planning.event.HspSysExtChangeHandler.actionPoller(Unkno
    wn Source)
    at com.hyperion.planning.event.HspSysExtChangeHandler.run(Unknown Source
    Can not get JDBC connection for SYS external changed actions.
    Can not get JDBC connection.
    Pls provide Solution

    Hi John,
    though i am trying with SQl server authentication with different user but still status is same of planningSystemDB.properties
    SYSTEM_DB_DRIVER=hyperion.jdbc.sqlserver.SQLServerDriver
    SYSTEM_DB_URL=jdbc:hyperion:sqlserver://neeraj-PC:1433
    SYSTEM_DB_USER=windowsAuthentication
    SYSTEM_DB_PASSWORD=CAFBAEFNBGEAABHEDOADFKADACBGBIFHBLCDFBAFFH
    SYSTEM_DB_CATALOG=plandb
    SYSTEM_DB_TYPE=SQL
    INSTANCE=
    my steps:
    Using SQL Server Management Studio
    Changed Widows authentication to SQL server authentication mode
    In SQL Server Management Studio Object Explorer, right-click the server, and then click Properties.
    On the Security page, under Server authentication, select the new server authentication mode, and then click OK.
    In the SQL Server Management Studio dialog box, click OK to acknowledge the requirement to restart SQL Server.
    In SQL Server Management Studio Object Explorer, right-click the server, and then click Properties.
    On the Security page, under Server authentication, select the new server authentication mode, and then click OK.
    In the SQL Server Management Studio dialog box, click OK to acknowledge the requirement to restart SQL Server.
    To restart SQL Server from SQL Server Management Studio
    To enable the sa login by using Management Studio
    In Object Explorer, expand Security, expand Logins, right-click sa, and then click Properties.
    On the General page, you might have to create and confirm a password for the sa login.
    On the Status page, in the Login section, click Enabled, and then click OK.
    In Object Explorer, expand Security, expand Logins, right-click sa, and then click Properties.
    On the General page, you might have to create and confirm a password for the sa login.
    On the Status page, in the Login section, click Enabled, and then click OK.}}}
    anything else should i change.................

  • Reading .txt file from remote using abap?

    Hi,
    I must read a .txt file from remote server automatically.
    I have path and name of .txt file. Remote system asks username and password.
    In abap is it possible to give username and password for reading .txt from remote server?
    Remote server and sap server are not in same domain.
    How can i do that?
    Thanks.

    Hi Cemil ,
      You can try using the FM RZL_READ_FILE_REMOTE_SH.
    This is an option i found ,  but i have really not tried it out .
    Regadrs
    Arun

  • How to retrieve full flash solution from WSP if not than how to retrieve ascx files from Template folder in SharePoint 2013 ?

    How to retrieve ascx file from the Template folder in SharePoint2013
    My issue is, I have WSP only so I changed into zip and got my all web parts and also one dll file after that decrypted dll and got some C# code
    mixing with some system generated code but not ascx file that is for front-end part. So my question is how we can retrieve full flash solution if not, at least ascx files So if we were on SharePoint 2010 we could have got those file from __Template__
    folder but It’s on SharePoint 2013 and not able to get ascx.
    If we can do so, than will be easy to get the task to be done
    Suggestions would highly be appreciated. Thanks in Advance.
    Ashish

    Hi Amit,
    you can not move specific changes from Dev to production.
    but you can follow this process to make your workflow as it is as in Dev:
    Create a new workflow on the new list in Product.
    Create at least one step, one condition and one action in this workflow.
    1. In Dev server open your .xomal file as XML and copy the entire contents.
    2.In Production server Open your .xoml file as XML and Paste the entire contents
    3. repeat this operation for the xoml.rules file
    4.Double click the .xoml file for the new workflow to open the workflow in the Workflow Designer and click Check Workflow to verify no errors and then click Finish to ensure the workflow is saved.
    Whenever you need to make changes apply the same.
    Please Mark Answer and Vote me if it will to resolve your issue

  • Why can't I open and retrieve my files from iPhoto and my address book after importing the files from my Power mac G5 to my new Mac Pro? I get a warning that says the new OS on my Pro doesn't open files from a Power Mac. Any idea how I can fix this?

    Why can't I open and retrieve my files from iPhoto and my Address Book after importing the files from my Power Mac G5 to my new Mac Pro? I get a warning that says the new OS on my Pro doesn't open files from a Power Mac. Any idea how I can fix this?

    For your addressbook, export the files to vCard on the PowerMac, then bring them over to your Mac Pro. For your iPhoto, copy the Users -> yourname -> Pictures folder to your Desktop on the Mac Pro, and open iPhoto on the Mac Pro holding the command and option keys.  Select the library file from that Pictures folder and open it.  It should import all the pictures into iPhoto as part of the rebuild process.  Other PowerPC to Intel migration issues are covered here: https://discussions.apple.com/docs/DOC-2295

  • How can I generate and/or retrieve log files from iPad

    How can I generate and/or retrieve log files from iPad?
    OBS!
    There are NO files apearing in ~/Library/Logs/CrashReporter/MobileDevice/<name of iPad> so where else can i find it?
    I want to force it to produce a log, or find it within the iPad.
    It is needed for support of an app.

    Not sure on porting out the log data, but you can find it under General->About->Diagnostic&Usage->Diagnostic&Usage Data.  It will give you a list of your log data, and you can get additional details by selecting the applicable log you are looking for.  Hope this helps.

  • I am using the desktop screensaver and a file from dropbox for photos.  Does the list of screen savers actually use the file, or just link to it.  If I delete the file from the dropbox, will the screen saver be lost?

    Using the desktop slideshow, I have added a file from dropbox for the slideshow.  If I delete the dropbox file, does that delete the file from the list on the slideshow?  Do I need to leave the file on the computer itself rather than in the dropbox and then delete it from the dropbox?

    If you are going to delete the file from Dropbox, you will need the file on your computer.
    You will probably need to put the file in Library/Screen Savers

  • How can i export a 24bit avi file from photoshop for mac?

    how can i export a 24bit avi file from photoshop for mac? i have a client that specificly needs the files to be avi and in 24bit what are the settings that i need to use to export the video using photoshop on a mac?

    Hello,
      To make a 24-bit AVI file in Photoshop, go to File>Export>Render Video. Then, under File Options, choose AVI from the Quicktime Export drop-down menu. Click the Settings button. Click the Settings button in the AVI Settings window. Change Compression to None, and then choose "Millions of Colors" from the Depth drop-down under Compression.
      The Millions of Colors option is for 24-bit video (8-bit R+G+B channels, 8x3=24). Millions of Colors+ is for 32-bit video (24-bit video plus an 8-bit alpha channel).
    -Brett

  • Product Instance Registration Error: "System Failure: Error while retrieving xml file from database"

    Hi S9 installation Gurus,
    Please try to resolve this long awaited issue with Planning installation as this is purely configuration related issue.
    Detail of Problem:-
    After Susessful configuration of
    1) Foundation Services (Hyperion Shared Services)
    2) Essbase administration services
    3) Essbase Server
    4) Hyperion reporting and analysis
    5) Planning -----> Product options, Register with shared services, configure database, deploy to application server (Appache)
    Error Point: when i tick ckeck box in front of Product instance registration
    click next
    create instance
    click next
    instance name-Plan1
    Web tier host name: my machine name (neeraj-pc, as i installed locally all component of hyperion)
    server port: 8300 (system suggesting)
    tick on active instance
    click next
    Error Pop Up "System Failure: Error while retrieving xml file from database"
    Details of PlanningSystemDB (file :- \Hyperion\common\config\PlanningSystemDB.properties)
    SYSTEM_DB_DRIVER=hyperion.jdbc.sqlserver.SQLServerDriver
    SYSTEM_DB_URL=jdbc:hyperion:sqlserver://neeraj-PC:1433
    SYSTEM_DB_USER=puser
    SYSTEM_DB_PASSWORD=GGAKFJ
    SYSTEM_DB_CATALOG=p1db
    SYSTEM_DB_TYPE=SQL
    INSTANCE=
    Note: puser (SQL Authenticated user)
    Thanks
    Kumar
    Edited by: user10385300 on Dec 4, 2008 5:44 AM

    This has been resolved at :- Product Instance Registration Error Message: "System Failure: Error while retrieving xml file from database"
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Is it possible to retrieve deleted files from the cloud i.e. contact list?

    Is it possible to retrieve deleted files from the cloud i.e. contacts?

    If you have an iCloud backup of an iOS device that was made while the contacts were still on it, you may be able to restore them from the backup by following this user tip from Winston Churchill: https://discussions.apple.com/docs/DOC-4841.

Maybe you are looking for