Copy folder embedded in jar

Hi,
I developed an application that produces single output jar file with a resource folder named "test" embedded
in the jar. The user needs to provide a destination location and the content of the folder "test" is supposed to be copied to the location.
How can I access the folder "test" and all of its content.
Thanks.

Possibly a simpler way to approach getting the resource names inside the test directory, is to write them to a file that is included within the jar. This is fairly simple if building the project using Ant (which can be run from the command line, but comes built-in to most IDEs).
Another approach (which I do not recommend) is to use the classes of the [Zip package|http://java.sun.com/javase/6/docs/api/java/util/zip/package-summary.html] to iterate the ZipEntrys, looking for resources in the test directory.
Once you have the resource names, are you clear on the rest of the process required?

Similar Messages

  • Copy & paste embeded object to file system

    Cross-post at:
    http://stackoverflow.com/questions/27685791/copy-paste-embeded-object-to-file-system
    Background:
    I wrote a large piece of VBA code in an Excel workbook to help handle a lot of repeating jobs. I found it is painful to maintain and modify the code by using the "pool" VBA Editor. Then, I decided to move those VBA code to C# solutions, which I
    suppose I can benefit from the modern editor - Visual Studio.
    Problem:
    Although I don't know too much about VBA, I know even less about C#. Hence I got some problem when I try to "translate" my VBA code to C#, and here is one of them:
    I create a document-level solution for Excel. I need to embed some files (.cab, .exe) into the solution, so when I run a method (e.g. by clicking a button), those files will be copied to the file system, and do some job.
    In VBA, I embedded those files in the Excel workbook, then I can copy the embedded objects to the clipboard by using the following VBA code:
    Sheet1.OLEObjects("obj_cab").COpy
    And then I can paste the object to the file system by using the following VBA code:
    CreateObject("Shell.Application").Namespace("C:\Sample\").Self.InvokeVerb "Paste"
    In the C# solution, I can use the following equivalent method to copy the embedded object to the clipboard:
    Microsoft.Office.Interop.Excel.OLEObject OLEobj = (Microsoft.Office.Interop.Excel.OLEObject)sheet1.OLEObjects("obj_cab");
    OLEobj.Copy();
    Then I stuck here, I don't know how to get this object from clipboard and put it to the file system. The 'CreateObject' method does not exist in C#.
    Anyone can help? Either a better way to embed those files or a working way to paste those objects (files) from clipboard to the file system?
    Thanks a lot!

    Hi FantaC,
    It's possible to save the oleobject to the disk. But it's not very simple. Because when you call the Copy method of OLEObject to clipboard, it's actually not the exact the oleobject file itself, it's actually a wrapper of the file, it means that it has different
    file headers and some other information from the original oleobject file.
    To save oleobject on the disk, you need to analyze the byte array by yourself, this would be a little complicated. You could check the answer in this thread for the code sample:
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/1ab7a178-8021-4c67-a14b-5031a254fd9c/saving-oleobject-content-to-a-file
    The original poster of this thread also write a blogpost about this, you can check it here:
    Saving OLEObject Content To File
    Detailed information and code samples are provided in this blogpost.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • The Java load in database SID / hostname has not been configured yet. You cannot run an installation from the System Copy folder with this load

    Dear Gurus,
    We are facing the below issue when performing a homogeneous system copy of NW 7.0 system using backup/restore method for DB6 system.
    The Java load in database <SID>/<hostname> has not been configured yet. You cannot run an installation from the System Copy folder with this load.
    We went through the SAP Note http://service.sap.com/sap/support/notes/2049842, and followed the same but no luck.
    We updated the Kernel to the latest, but still no luck.
    Request for your quick help as we have to complete it by EOD today.
    Thanks a lot in advance.
    Best Regards,
    Anuj

    Hello Ashutosh ,
    Thanks for your reply.
    We have gone followed the below sequence:
    SCS Installation
    Database Instance Installation using backup/restore method
    CI installation. -> getting error, when we provide the Java Components DVD.
    Best Regards,
    Anuj

  • Copied folder smaller than the original one

    Hi, when I copy my folder of Logic song material (size approx. 4,55 GB, located on the desk) to an external Harddisk (WD ´my book´, I guess Fat32, brandnew and not formatted under OS X) or via my inhouse network (on a windows PC with NTFS), the copied folder is smaller than the original one - approx. 4,2 or 4,3 GB then.
    Is that normal or are files lost during the copying? I need help with this urgently, because I have to do the backup.
    My system: PowerMac G5 Dual, 2,5 GHz, 3 GB RAM, Tiger (newest version), nothing special.
    Thank you für your help,
    PE

    Philip
    Is that normal or are files lost during the copying? I need help with this urgently, because I have to do the backup.Copying can certainly reduce the space taken, because fragmentation is reduced.
    If you want a one off count of your folder, you can do this:
    Open the Terminal (from /Applications/Utilities) and type
    cdNow type a space, and then drag the folder you are interested in to the Terminal window. It will fill in the path automatically, so you will see something like
    cd /Users/jdoe/Documentsfor example. Now type a return, and then copy and paste the following, as one line, into the Terminal window:
    <pre>echo "`find . -type f \! -name ".*" | wc -l` files and `find . -type d | wc -l` folders"</pre>Now press return, and wait!
    As an indication, for my Home folder it takes about 35 seconds on a 600MHz iBook (slow drives in these laptops) to tell me I have 16631 files and 3920 folders. The command does not count dotfiles, such as ".DS_Store", deliberately, so there may be small discrepancies.

  • Copying folder options

    when copying folder to another drive for backup.. why let me get halfway through an operation before telling me the folder name exists somewhere in the structure and then the ONLY option is to cancel the copy half way through.
    its annoying that upper/lower differences cause copying errors, but not the end of the world.
    its is extremely frustrating to have no other option than to click 'okay' and have the whole operation abort halfway through. I had selected 1.5 TB of information to back up across many nested folders. Now that the operation has cancelled i have to manually delve into the folders to find which ones finished copying. and to find where the duplicate folder exists.
    This copy operation was many hours in. and to restart this is a big waste of my time.

    Triple-click anywhere in the line below on this page to select it:
    { diskutil list; echo; diskutil cs list; } | open -f -a TextEdit
    Copy the selected text to the Clipboard (command-C).
    Launch the Terminal application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Terminal in the icon grid.
    Paste into the Terminal window (command-V).
    A TextEdit window will open with the output of the command. If the command produced no output, the window will be empty. Post the contents of the TextEdit window (not the Terminal window), if any — the text, please, not a screenshot. The title of the window doesn't matter, and you don't need to post that.

  • General procedure on copying folder from PCD

    Hello All,
    Whats the correct method for copying folder, iviews etc.
    I have just imported the latest version of ESS and MSS.  And am going to copy the folder using a delta link.
    Do I then have to change the ID of the object and the object prefix?
    If this is the case does it have to be done for all folder, iviews, pages etc?  Or can I just leave them as the same name as the version i copied it from?
    Thanks,
    Nick.

    Hi Nick,
    I am sorry it took so long. I did a little research and apparently there really is no official recommendation right now.
    The settings for homepage customizing in the backend are only supposed to be examples / templates, so I guess you could say that the recommendation is still to copy the business packages in the portal via content mirroring to your namespace. The problem with that is -- like you said -- that you have to adjust all the settings in the backend for this.
    In my opinion the best way right now is to leave the PCD structure as it is and use the "examples" from the backend. Only if you intend to create your very own structure would it be reasonable to use the content mirroring and adjust all the links -- but this is only my opinion.
    Regards,
    Holger.

  • Copy folder from jar into temp directory

    There are some files inside the folder folder kept in the jar file, which I am copying one by one to temp directory as shown in my below code. Could someone please tell me how do I use a loop to copy all the files from the folder folder to temp directory
    String path = System.getProperty("java.io.tmpdir");
    File dir = new File(path+"\\folder"); 
    dir.mkdirs();
    InputStream is1=Main.class.getClass().getResourceAsStream("/input/folder/file1.txt");
    try
         File.createTempFile("file1", ".txt",dir.getCanonicalFile());       
    catch (IOException e)
         e.printStackTrace();
    File dstfile1=new File(dir,"\\file1.txt");
    dstfile1.deleteOnExit();
    FileOutputStream fos1 = new FileOutputStream(dstfile1);
    int b1;
    while((b1 = is1.read()) != -1)
         fos1.write(b1);
    fos1.close(); 
    InputStream is2=Main.class.getClass().getResourceAsStream("/input/folder/file2.txt");
    try
         File.createTempFile("file2", ".txt",dir.getCanonicalFile());       
    catch (IOException e)
         e.printStackTrace();
    File dstfile2=new File(dir,"\\file2.txt");
    dstfile1.deleteOnExit();
    FileOutputStream fos2 = new FileOutputStream(dstfile2);
    int b2;
    while((b2 = is2.read()) != -1)
         fos2.write(b2);
    fos2.close();

    Yes there is! Use ZipFile!!!
          * Copies an entire folder out of a jar to a physical location. 
            private static void copyJarFolder(String jarName, String folderName) {
              try {
                   ZipFile z = new ZipFile(jarName);
                   Enumeration entries = z.entries();
                   while (entries.hasMoreElements()) {
                        ZipEntry entry = (ZipEntry)entries.nextElement();
                        if (entry.getName().contains(folderName)) {
                             File f = new File(entry.getName());
                             if (entry.isDirectory()) {
                                  f.mkdir();
                             else if (!f.exists()) {
                                  if (copyFromJar(entry.getName(), entry.getName())) {
                                       System.out.println("Copied: " + entry.getName());
              catch (IOException e) {
                   e.printStackTrace();
          * Copies a file out of the jar to a physical location. 
          *    Doesn't need to be private, uses a resource stream, so may have
          *    security errors if ran from webstart application
         public static boolean copyFromJar(String sResource, File fDest) {
              if (sResource == null || fDest == null) return false;
              InputStream sIn = null;
              OutputStream sOut = null;
              File sFile = null;
              try {
                   fDest.getParentFile().mkdirs();
                   sFile = new File(sResource);
              catch(Exception e) {}
              try {
                   int nLen = 0;
                   sIn = /***YOURCLASSNAME***/.class.getResourceAsStream(sResource);
                   if (sIn == null)
                        throw new IOException("Error copying from jar")  +
                             "(" + sResource + " to " + fDest.getPath() + ")");
                   sOut = new FileOutputStream(fDest);
                   byte[] bBuffer = new byte[1024];
                   while ((nLen = sIn.read(bBuffer)) > 0)
                        sOut.write(bBuffer, 0, nLen);
                   sOut.flush();
              catch(IOException ex) {
                   ex.printStackTrace();
              finally {
                   try {
                        if (sIn != null)
                             sIn.close();
                        if (sOut != null)
                             sOut.close();
                   catch (IOException eError) {
                        eError.printStackTrace();
              return fDest.exists();
         }-Tres
    Edited by: FBL on Oct 5, 2007 6:59 AM

  • How does an "iPhoto Library Copy" folder get created? It has an icon that looks like a stack of photos with a pink flower.  It contains all my photo's (as far as I can tell) and the original "iPhoto Library" only contains "AlbumData.xml?

    I upgraded to Lion last month AFTER wiping the hard drive for the second time on my 2011 macbook pro.  I am now suspecting that transferring my photos (I have over 8,000 saved on sd cards) to my computer is bringing all this trouble. 
    I was able to rectify some problems by dragging import file from library to desktop etc... But I am worried that these Copied Libraries and recovered photo files and AlbumData.xml file are a sign of something darker loomng ahead...

    Sorry but we have no idea what's going on, or gone on, on your machine. Neither can we see it. We only have your somewhat sketchy post. You mention that you can rectify "some problems", you mention "all this trouble" but neglect to mention what these problems and trouble actually are. So, I'm afraid it's hard to respond to your post in a meaningful way.
    A couple of thoughts: 8,000 photos is not a problem. iPhoto is good for 250,000 in any one library. So, unless you have very limited HD disk space, this is not the source of whatever issues you are having.
    If you're dragging parts of the iPhoto Library around the place, yes there could be trouble ahead. Don't change anything in the iPhoto Library Folder via the Finder or any other application. iPhoto depends on the structure as well as the contents of this folder. Moving things, renaming things, deleting them or otherwise making changes will prevent iPhoto from working and could even cause you to damage or lose your photos.
    There are two ways to get a copied library:  one is to duplicate the Library yourself (either accidentally or deliberately) or while restoring from back up.
    Regards
    TD

  • How to add empty folder in a jar file ?

    Well
    I know how to add files in a jar file but I cannot add empty folder.
    I would like to do this so that when I get back the jar file I can have all the structure of the save main folder.
    I also test that it is possible to do that on line with the "jar" command.
    Does any of you know how to do this programacticaly ?
    Thanks in advance

         JarOutputStream jos = // ...
         jos.putNextEntry(new JarEntry("directory/"));
         jos.closeEntry();
         jos.finish();
         jos.close();on the command line:
    jar -tf <your_jar_file.jar>

  • Can't copy folder to hard drive. Why?

    I can't copy a folder from an external drive to the hard drive!
    A message comes up: "The operation can't be completed because an item with the
    name  ".DS_Store" already exists."
    What does this mean and what do I have to in order to be able copy the folder?
    Have been using Macs for many years and have never come across this issue before.
    Thanks,
    iHope

    Looks like Wikipedia discusses this file:
      http://en.wikipedia.org/wiki/.DS_Store
    Perhaps you are logged in as a regular user and some permissions on that file are preventing you from over writing it.  Maybe a different account has full permissions over the existing .DS_Store file.
    You could try creating a new Top level Folder and copy into this new folder.
    Or you could log into an Administrator account and using the Terminal App delete the .DS_Store file at the comand prompt.
    You could also try deleting the .DS_Store file from the Folder on the external drive,
       using the Terminal App would be the easiest
        to delete a file that is invisible to the Finder App.
    example:
      prompt> cd /Volumes/System/Drop/
      prompt> ls -al .DS_Store
    -rw-r--r--@ 1 user  wheel  12292 Dec 27 16:12 .DS_Store
      prompt> rm .DS_Store

  • Cannot view media in Pages document after copying folder to desktop

    I have created a document in Pages which includes video, which is saved in a folder called Assignments.I also have a folder marked Pictures and Videos which contains the media from the document contained within the Assignments folder.
    However, the problem I am having is that when I copy the Assignments folder to the desktop and open up the pages document, Pages tells me that the media cannot be found, even though I have coped the Assignments folder to the desktop.
    How could I go about solving this problem, as it's really quite irritating as nothing has changed other than me copying the folder to the desktop.
    Thank you in advance

    I use an other scheme.
    I store the document and the media files in a disk image so, I may move the complete set as I want.
    Yvan KOENIG (VALLAURIS, France) mardi 28 septembre 2010 22:03:33

  • Copy Folder with Joins. Export/Import Folder with joins. In EUL.

    Ok, I've got a custom folder which has been made up by dragging items from 2 or 3 other folders into it.
    It then has some joins of it's own, quite a few.
    When trying to create a workbook from it, it takes 9 mins to run a query.
    I need to work out what is slowing it down. If I create the same workbook against the folder which has the majority of the items in the custom folder, it runs instantly.
    So I suspect it is one of the joins causing it.
    My plan was to duplicate the folder, then remove joins until I find out which one is causing it.
    However, if I cut n paste the folder, I get a copy without the joins.
    If I export the folder and import it I get a copy without the joins.
    Question then - how can I get a copy of a folder WITH the joins ?
    I'm slightly concerned that when I export my EUL from the dev database and import it into the live database that I'm not going to get any joins since the export and import into the dev database is not retaining the joins.
    Anyone ?

    Hi,
    The preferences for Disco Plus are set in the pref.txt file on the apps server and for Disco Desktop in the Windows Registry. I think the defaults are set on so unless you have changed them this is unlikely to help.
    I think I read somewhere that the 11g optimiser will remove unused outer joins or where there is a foreign key constraint. I may have made that last bit up as I cannot find a reference to it, but it may be worth exploring.
    To speed things up you could look at why this join is slowing things down. It could be that you need an index on the join column.
    The join actually is used, in that it has to check in the other table that a record exists. This is why Discoverer cannot remove the join from the complex folder query. If it did and there where no matching records in the other table then you would get a different result.
    Rod West

  • Copying Folder to Multiple User Document Folders

    I can't find anything in the forums which exactly covers my situation, so I apologize if I am covering old ground.
    Is it possible to copy a folder and it's contents to a users document folder on multiple computers via ARD 2.X?
    In other words, I want to take a folder and use ARD 2.x to copy that folder to say fifty unique users' document folder over the network without having to enter a new command for each user the folder is copied to.
    Does anyone have an idea as to how to do this?

    You might try copying it to Users/Shared. That way it is available to everyone on the machine and you only have to copy it once to each computer. What kind of a folder is it? Some apps (like Word) have template folders that all users get when they load the app, so you could just copy your items to that folder, depending on what kind of file it is.

  • How to copy folder with files and subfolders within it  to another folder

    how to copy a folder with files and subfolders within it to another folder

    http://javaalmanac.com/egs/java.io/CopyDir.html?l=new

  • Portal Content Copy Folder Error

    Hi,
    In Portal Content Admin, the folders <b>Key Account Manager</b> & <b>CRM</b> are provided by business package and located under <i>Content Provided by SAP -> specialist</i>.
    When these folders are copied to another folder for further customization, <b>Key Account Manager</b> is copied successfully but for <b>CRM</b>, following error message is shown:
    Copy: CRM
    Error
    Source object not found. It may have been deleted.
    Then, I tried to copy <b>CRM</b>'s subfolder. Small folders (packages, pages, roles, templates) completed successfuly but the complicated folders (iViews & Worksets) failed with the same error message.
    Although I can try to copy the sub-folders one by one, it is too tedious & error-prone.
    How can the <b>CRM</b> folder be copied completed?
    Regards,
    Tony

    The reason for the error is still unknown.
    By the way, with the help of Content Mirroring, this error is not an issue for me anymore. Using Content Mirroring instead of Copy & Paste is also suggested by SAP document: http://help.sap.com/saphelp_nw04s/helpdata/en/ed/fd25c7c14c4094a9fbb19851d79dd1/content.htm

Maybe you are looking for