How to Read all files inside resource Folder inside Jar?

I have a Jar file,,,, The program reads for resource files in the resource folder inside the Jar. I want my program to read all files inside this folder without knowing the names or the number of files in the folder.
I am using this to make an Applet easy to be updated with spicific files. I just want to add a file inside the resource folder and Jar the program and automatically the program reads what ever is in there!!
I used the File class to get all file names inside the resource folder. it works fine before Jarring the program. After I jar I recieve a URI not Herarichy Exception!!
File fold=new java.io.File(getClass().getResource(folder).toURI());
String[] files=fold.list();
I hope the question is clear!!

How to get the directory and jar file that you class resides in:
// returns path and jarfile (ex: /home/mydir/my.jar)
public String getJarfileName()
        // Get the location of the jar file and the jar file name
        java.net.URL outputURL = YourClass.class.getProtectionDomain().getCodeSource().getLocation();
        String outputString = outputURL.toString();
        String[] parseString;
        int index1 = outputString.indexOf(":");
        int index2 = outputString.lastIndexOf(":");
        if (index1!=index2) // Windows/DOS uses C: naming convention
           parseString = outputString.split("file:/");
        else
           parseString = outputString.split("file:");
        String jarFilename = parseString[1];
       return jarFilename;
}If your my.jar was in /home/mydir, it will store "/home/mydir/my.jar" in jarFilename.
note: getLocation returns "file:/C:/home/mydir/my.jar" for Windows/DOS and "file:/home/mydir/my.jar" for windows, thus why I look for the first and last index of the colon so I can correctly split the string.
If you want to grab a file in the jar file and get an InputStream, do the following:
import java.io.*;
import java.util.Enumeration;
// jar stuff
import java.util.jar.*;
import java.util.zip.ZipEntry;
public class Jaris
   private JarFile jf;
   public Jaris(String jarFilename) throws Exception
       try
                       jf = new JarFile(jarFilename);
       catch (Exception e)
            jf=null;
            throw(e);
   public InputStream getInputStream(String matchString) throws Exception
       ZipEntry ze=null;
       try
          Enumeration resources = jf.entries();
          while ( resources.hasMoreElements() )
             JarEntry je = (JarEntry) resources.nextElement();
             // find a file that matches this string from anywhere in my jar file
             if ( je.getName().matches(".*\\"+matchString) )
                String filename=je.getName();
                ze=jf.getEntry(filename);
      catch (Exception e)
         throw(e);
      InputStream is = jf.getInputStream(ze);
      return is;
   // for testing the Jaris methods
   public static void main(String[] args)
      try
           String jarFilename=getJarfileName();
           Jaris jis = new Jaris(jarFilename); // this is the string we got from the other method listed above
           InputStream is=jis.getInputStream("myfile.txt"); // can be used for xml, xsl, etc
      catch (Exception e)
         // this is just a test, so we'll ignore the exception
}Happy coding! :)
Doc

Similar Messages

  • How  to read all files  under a folder directory in FTP site

    Hi Experts,
    I use this SQL to read data from a file in FTP site. utl_file.fopen('ORALOAD', file_name,'r');
    But this need to fixed file name in a directory. However, client generate output file with auto finename.
    SO do we have any way to read all file by utl_file.fopen('ORALOAD', file_name,'r');
    We need to read all file info. because client claim for security issue and does not to overwirte output file name,
    we must find a way to read all file in output directory.
    Thanks for help!!!
    Jim

    If you use Chris Poole's XUTL_FTL package, I believe that contains functions that allows you to query the directory contents.
    http://www.chrispoole.co.uk/apps/xutlftp.htm
    Edited by: BluShadow on Jan 13, 2009 1:54 PM
    misread the original post

  • How to read all files from a folder Diadem

    Hello,
    Can somebody tell me how to load automatic some .csv file form a folder to Data Portal in Diadem.
    I do some tests and during this tests I record  data ( .csv files), files that I load manual now (*FileNameGet  command), but I want when the tests are done and I load the script, then atomatic to load the csv files, analyze and build the report.
    Please advice me how can I do that.
    Thank you
    (Attached you have my program)
    Solved!
    Go to Solution.
    Attachments:
    scripts.zip ‏10 KB

    Duplicate Post here:
    http://forums.ni.com/ni/board/message?board.id=60&message.id=10467#M10467
    David_L | Certified LabVIEW Architect
    LabVIEW Tools Network | LabVIEW Tools Network Developer Center

  • How to read the file from a folder.

    Hi All,
    How to read the file from a folder or directory from the non sap server / remote server.
    Regards
    Sathis

    open dataset filename for input in text mode
                         encoding default.
    filename is character type variable with the destination filename.
    Edited by: Jino Augustine on Apr 19, 2010 1:31 PM

  • Read all Files from a Folder on Server

    Hi,
    Can anyone help me in finding if there's any way to read all files in a folder on the server?Any Function module or anything.
    Thanks

    On App server?  Try this sample program.
    report zrich_0001 .
    data: begin of itab occurs 0,
          rec(1000) type c,
          end of itab.
    data: wa(1000) type c.
    data: p_file type localfile.
    data: ifile type table of  salfldir with header line.
    parameters: p_path type salfile-longname
                        default '/usr/sap/TST/DVEBMGS01/data/'.
    call function 'RZL_READ_DIR_LOCAL'
         exporting
              name           = p_path
         tables
              file_tbl       = ifile
         exceptions
              argument_error = 1
              not_found      = 2
              others         = 3.
    loop at ifile.
      format hotspot on.
      write:/ ifile-name.
      hide ifile-name.
      format hotspot off.
    endloop.
    at line-selection.
      concatenate p_path ifile-name into p_file.
      clear itab.  refresh itab.
      open dataset p_file for input in text mode.
      if sy-subrc = 0.
        do.
          read dataset p_file into wa.
          if sy-subrc <> 0.
            exit.
          endif.
          itab-rec = wa.
          append itab.
        enddo.
      endif.
      close dataset p_file.
      loop at itab.
        write:/ itab.
      endloop.
    Regards,
    Rich Heilman

  • Newbie question -  How to read all files for a backup

    Hello all,
    I have two users on my iMac. I am an administrator and the other user is a Standard user.
    From my account, I wish to run backup software that will backup the entire "User" directory. The problem I am having is that when I run the backup software (fyi: iBackup),
    it complains that it cannot read the files in the other user's account.
    I notice that when I browse to the other user's account, all the directories in their home folder are locked.
    How can I run my backup software so that it can read all files in the User directory?
    Thank you kindly!
    Jeff
    17" iMac Core Duo   Mac OS X (10.4.6)  

    Hi kneecarrot !
    I don't know if this will suit your needs, but one easy way of backing up other user's stuff is via the terminal . If you have an admin accountm just use:
    sudo ditto -rsrcFork /Users /Volumes/"nameof_anotherharddrive"/Users
    This will perform an identical clone of all your users home direcories for backup purposes. To restore the bkd'up files, just reverse the lines:
    sudo ditto -rsrcFork /Volumes/"nameof_anotherharddrive"/Users /Users
    ATTENTION: Be aware that it will restore the files to the exact structure and contents it was when backed up, erasing all new and modified files!! You may however copy just the files/folders you want to recover, e.g.:
    sudo ditto -rsrcFork /Volumes/"nameof_another_harddrive"/Users/"usera"/Documents /Users/"user_a"/Documents
    IMPORTANT: As with all terminal commands... be careful, think twice and double-check the syntax. You may want to test with non-critical stuff or demo user accounts first.
    Good luck,
    Michael
    MacBook Pro   Mac OS X (10.4.6)   2 Gig RAM

  • 10.6.4:  how to unlock all files in a folder

    hi,
    how do you unlock all files inside a folder?
    thank you..

    thank you.. (I wonder why you can't just do it by getting info on the folder, then saying, unlock all files inside.. (u can do like that in windows) this is always more practical than having to select all files (and accidentally opening them, or something...-) in windows you can select a folder and then say, (un)lock all files and and dirs -- and subdirs and files inside -- inside this folder.. can u do something like this in mac os? if not, that's not very good.. (I guess on the mac would need to find unix commands for doing something like this..)
    they really need to consider this for future versions, this is a no-brainer...;-)
    thank you..

  • How to read .mdb file from shared folder

    Hi All,
    In one of my local computer I have a shared folder and within the folder I have a .mdb file. Now I am trying to read that file from MII. I have tried with Get_File_List action block. I am providing the following information to Get_File_List
    Folder :
    <Computer Name>\<Shared Folder Name>
    Mask: .mdb
    But in return of Get_File_List, I am not getting any file related information. It is only providing like below
    <Rowsets>
    <Rowset>
    <Columns>
    <Column Description="Name" MaxRange="0" MinRange="0" Name="Name" SQLDataType="1" SourceColumn="Name"/>
    <Column Description="Date" MaxRange="0" MinRange="0" Name="Date" SQLDataType="93" SourceColumn="Date"/>
    <Column Description="Size" MaxRange="100" MinRange="0" Name="Size" SQLDataType="4" SourceColumn="Size"/>
    <Column Description="LastWriteDate" MaxRange="0" MinRange="0" Name="LastWriteDate" SQLDataType="93" SourceColumn="LastWriteDate"/>
    <Column Description="ReadOnly" MaxRange="1" MinRange="0" Name="ReadOnly" SQLDataType="4" SourceColumn="ReadOnly"/>
    <Column Description="FullPath" MaxRange="0" MinRange="0" Name="FullPath" SQLDataType="1" SourceColumn="FullPath"/>
    </Columns>
    </Rowset>
    </Rowsets>
    Can anybody suggest me how to achieve it.
    Thanks in advance
    Chandan

    Hi Chandan,
    Specify the mask as *.mdb and try.
    Thanks,
    Dipankar

  • How to move all files from a folder for a user to a centralized folder on a core server with a GP

    Hello,
    I was curious if someone know how to move all the files of a user "local" profile on a Terminal Server to that of a centralized server where the "local" profile of like the user desktop, favorites, setting, etc are stored in the event
    the local profile on the TS become corrupt it can pull from this server...
    The problem I have is no matter what I tell users to save there files to our Y drive that is a folder that is synced
    across all 6 of our TS servers, users still store files on there desktops, so as you can imagine if one day they are on one server, then next day they could be on another and there files aren't the same.... hence the reason why I want to move all there files
    to the centralized server so when I redo the profiles from scratch on the TS server in the farm they suck files from the core server and have all of the files they are used to having.... 
    So I was curious and I've heard from some this is possible in a GP, but I'd like to move the contents of all 6 TS for
    each user or if I have to d this on  per user basis I will, just looking for a way to move the files....

    Hi Trevor,
    To move all users’ desktop to a server, we can use Folder Redirection to do this. The path for Folder Redirection is:
    [Group Policy Object Name]\User Configuration\Policies\Windows Settings\Folder Redirection
    In this situation, we can choose to redirect desktop to the root of a network file share or a folder on a network share.
    Regarding how to configure this, the following article can be referred to for more information.
    Configuring Folder Redirection
    http://technet.microsoft.com/library/cc786749.aspx
    Hope it helps.
    Best regards,
    Frank Shen

  • File Utility - Find operation; How to retrieve all files in a folder?

    I am using Find operation of FileUtility service to count the number of files present under a given folder.
    I can not find the correct Regular Expression to match all files.
    The Adobe documentation mentions that * character is default which matches all files/folder within the Directory. However, If I leave * unchanged, I'm getting an error "Incorrect Regular Expression syntax".
    I have tried different combinations, nothing seems worked.
    Can anyone assist me on this?
    Thanks,
    Nith

    Hi,
    You can use the following syntax to get the list of all files:-
    \w*\.\w*
    Yow can alslo go through the following material for details on Regular Expressions:
    http://help.adobe.com/en_US/livecycle/9.0/workbenchHelp/help.htm?content=000582.html
    Thanks

  • Read All Files in a Folder

    I have a large set of data. Many don't have similar names at all. They
    all have the same data form (a 100x2 array for example).
    Is there a way to have a VI read all the files, one after another,
    automatically? It's a lot easier when the files are the same name, but
    ending/starting with different ID numbers. If they're all different,
    what can I do?
    Also, is it possible to create a VI, so that a file 'dropped' onto the
    VI's icon, will cause it to process the data? I'm not sure if this is
    a Labview or MS Windows problem.
    Thank you for your time.
    -Dorian
    [email protected]
    Please post if possible, to share.

    Dorian;
    You can simplify this if all your files are in the same directory. Check the example attached that read all .jpg images in a directory and display them in a picture control. Enter the directory path before running.
    As for your second question, it can be done, but I think (I might be wrong) that you must convert your vi into an executable. Check the following example:
    Get Calling File Path from Command Line
    Best regards;
    Enrique
    www.vartortech.com
    Attachments:
    image_show.vi ‏24 KB

  • Scripting: how to read all files in specific subfolders?

    Hello,
    via a Fireworks script (.jsf) I want to get all files in specific subfolders e.g. of "d:\images" to do something with these files (exporting as JPEGs).
    What are these commands?
    Thanks!
    carlos

    You would use Files.enumFiles:
    http://help.adobe.com/en_US/fireworks/cs/extend/WS5b3ccc516d4fbf351e63e3d1183c94988d-7ee8. html
    Aaron
    http://fireworks.abeall.com

  • How to list/read all files in a folder

    actually i want to list all the files/folders in a specified
    folder on server.
    please somebody suggest me how can I.

    ya actually i realize the scenario now.
    i work on flex with php.
    i'm going to do it with php now.
    but if i want to develop a desktop application with flex (
    actually i'm thinking of a photo gallery) without PHP/XML ( or
    other headaches for programming illiterates ) so that they simply
    put my swf application in their my pictures folder and enjoy it, I
    CANT DO IT RIGHT?????
    so SAD..... :(

  • How to move all files from a folder for a user to a centralized folder on a core server

    Hello,
    I'm curious if there is a batch file that can be made to move the contents that are setup like this....
    I'm having to redo a TS cluster and I'd like to make a batch file script that can be executed that moves the contents of say 'jsmith's local desktop profile @ \\NGTTS1\users\jsmith to a centralized folder on our roaming desktop profile server that saves
    all of the files for the desktops @ \\NGTFS1\users\jsmith.
    The problem I have is no matter what I tell users to save there files to our Y drive that is a folder that is synced across all 6 of our TS servers, users still store files on there desktops, so as you can imagine if one day they are on one server, then
    next day they could be on another and there files aren't the same.... hence the reason why I want to move all there files to the centralized server so when I redo the profiles from scratch on the TS server in the farm they suck files from the core server and
    have all of the files they are used to having.... 
    Now I know I can do this with a MOVE command I've just never done one to this exact.
    Hopefully someone knows the command to move all the contents of one folder on one server to the folder on a different server. I've already got the bulk of the coding done of the .bat script I just don't know this move command:
    would it be this:
    move \\NGTTS1\users\jsmith *.* \\NGTFS1\users\jsmith
    any help would be appreciated, I'm sure this is a easy command to do!
    This is the coding I have so far....
    @echo off
    color 0A
    title Moving Local Profile folder to Centralized Profile Folder on Core Server.
    :start
    echo Welcome, %USERNAME%
    echo What would you like to do?
    echo.
    echo 1. Moving Local Profile folder to Centralized Profile Folder on Core Server
    echo. 
    echo 0. Quit
    echo.
    set /p choice="Enter your choice: "
    if "%choice%"=="1" goto Move-user-profiles
    echo.
    if "%choice%"=="0" exit
    echo Invalid choice: %choice%
    echo.
    pause
    cls
    goto start
    :Move-user-profiles
    echo.
    set /p profile="Enter user profile: "
    move "\\NGTTS1\users\%profile%" *.* "\\NGTFS1\users\%profile%"
    echo moving files from local profile folder to FS1 profile server, stand-by...
    echo.
    goto cancel-special 
    :cancel-special
    set /p cancel="Type cancel to stop action: "
    if not "%cancel%"=="cancel" exit
    cls
    echo Action is cancelled.
    echo.
    pause
    exit

    In Windows we would do this using Group Policy.  There is a Policy setting that csn move the Desktop folder to any server you want to move it to.  Once set it will automatically do this for you.
    You should post in the Group Policy forum to find out how we use Group Policy to manage users profiles in Windows.
    You cannot use a script to relocate a users Desktop folder.  The desktop is locked by the time the users logon script is finished running.  It the desktop and profile are already being managed by Group Policy then this can only be done with GP.
    There are also numerous issues associated with deployment and re-deployment that you need to address  Post your questions in the Winows Deployment forum to get assistance with deployment issues.
    Again - want you are asking is not generally possible because of how Windows is designed.  This would only likely work on a simple system or on a stand alone PC and then only under a very limited set of circumstances.
    Use GP folder redirection to do this.  For deployment use Deployment Forum and for TS specific issues post in the RDS forum. 
    All of  this needs to be considered correctly for TS users inn a TS Cluster environment. (TS Cluster?? - not sure what you mean by that.
    ¯\_(ツ)_/¯

  • How to read all files' name in a directory and store in a string array?

    as title

    One possibility is to use the listFiles() method, using recursion if you want the files in the sub-directory also. Check API documentation for java.io.File.

Maybe you are looking for

  • Hp AIO app trouble finding printer.

    I recently downloaded HP AIO app for Apple device wireless printing my printer HP photo Smart C1580 is connected by ethernet to the router for some unknown reason this app does not seem to be finding my printer. Is there a answer to this? This questi

  • FTP Adapter - Send (Target)

    Hi, I have interconnect 9i standalone installation on HP-UNIX with most of the adapters installed. The integration scenario/flow of the data is: Source: DB Adapter Target: DB Adapter and FTP. I have multiple targets in the above scenario. The integra

  • Package owner - invalid packages

    Hello guys, I have this problem: I have two DB schemes A and B. I modified the code in both schemes. After compilation, many packages were invalidated. So I compiled all invalid packages, no compilation errors, everything ok. Now if I run this query

  • How to parameter BAPI_REPPROV_GETVARIABLES ??

    Hi Gurus I want to retrieve the selection variables of a query in an OLAP  BADI I think the way to do this is to call BAPI_REPPROV_GETVARIABLES . But  : How to find the SESSIONID it needs ? And : if we need the REPORTID to find the SESSIONID, how to

  • How to create distributed .exe of any CVI project

    How to create distributed .exe of any CVI project that we can execute in any system which doesn't have CVI installed