How to delete a jar file after loading image files from it

Hi,
How can I delete a jar file after some image files have been loaded? For example, say, I have "a.jar" which contains an image "a.gif" in the root directory of the c drive. I would like to get the image size and then delete the jar file. Here is the code snippet:
    URL url = new URL("jar:file:/C:\\a.jar!/a.gif");
    Icon icon = new ImageIcon(url);
    System.out.println("icon size ? " + icon.getIconHeight());
    File file = new File("c:\\a.jar");
    while(file.exists())
        file.delete();
        try
            Thread.sleep(100);
        catch (InterruptedException ignored)
    System.out.println("file deleted.");I get the image size correctly but just can not delete the jar file. Apparently the file handle is not released, but how to close it? Any hint will be appreciated.
Justin Jan

I am sure the URLConnection.defaultUseCaches is set before it is connected otherwise I should catch an IllegalStateException on conn.setUseCaches(false).
        try
            URL url = new URL("jar:file:/C:\\a.jar!/a.gif");           
         URLConnection conn = url.openConnection();
           conn.setDefaultUseCaches(false);
         conn.setUseCaches(false);
            Icon icon = new ImageIcon(url);
            System.out.println("icon size ? " + icon.getIconHeight());
            url.openConnection().getInputStream().close();
            System.gc();
         System.runFinalization();
            File file = new File("c:\\a.jar");
            while (file.exists())
                file.delete();
                try
                    Thread.sleep(10);
                catch (InterruptedException ignored)
            System.out.println("file deleted.");
        catch (Throwable t)
            t.printStackTrace();

Similar Messages

  • How to view the change immediately after a java file is modified without restarting server or redeploy?

              Hi All,
              How to view the change immediately after a java file that is used in jsp is modified
              without restarting server or redeploy?
              Moreover, it is better to keep the original session.
              Any suggestion is appreciated.
              Kammau
              

              Hi,
              In order to have a new version of a java class, the current classloader must be
              deleted and a new one created. This is what redeployment does. I believe that
              this is more of an issue with Sun's implementation of classloaders. You could
              ask BEA support (719.232.7878) and see if they have any plans to periodically
              check jar files to see if java class file timestamps and destroy and re-create
              classloaders on the fly.
              1) You will still have to accept the performance hit of destroying classloaders
              and creating new ones. There isn't any way around that.
              2) I would think you would want to have more explicit control in production and
              integration anyway.
              You can redeploy applications from the command line (script) file not just the
              console.
              Hope this helps,
              pat
              "Kammau" <[email protected]> wrote:
              >
              >Hi All,
              >How to view the change immediately after a java file that is used in
              >jsp is modified
              >without restarting server or redeploy?
              >Moreover, it is better to keep the original session.
              >Any suggestion is appreciated.
              >
              >Kammau
              

  • How do i transfer a compilation photo file from iPhoto consisting of canon(img) and lumix(p..) in the order i compiled them to a usb stick as at the moment it is putting all the lumix files after the canon files?

    I have a macbook pro 15 inch retina 16 gb 1600mhz 2.7intel i7 osx 10.8.5
    I have just put together an iPhoto file of wedding photos consisting of a compilation of images from my canon(img files) and lumix(p..files) I want to know how to transfer them to a usb stick in the order i compiled them as at the moment it is putting all the lumix files after the canon files which is not how i want to present them to the newlyweds?

    Files are ordered by the file-viewer being used.  What viewer are you using, and what data field are you sorting by?
    In Finder, as in most applications, you can select the data field to sort by clicking a column header.  Clicking the selected header will reverse the sort.
    This is the Aperture forum, but what applies to Aperture is likely also true for iPhoto:  if you want to be able to sort your files in a specific order in a file-viewer, you should give them names that allow for sorting in that order when the name field is selected as the data field to sort by.  In Aperture, one creates new files by exporting, and one uses a File Naming Preset to name the files.  The File Naming Preset can start with an ordinal count or a sequence number.  Either of which will allow you to retain your order when viewing your files in a file viewer.

  • After loading my photos from my iPhone to my mac iPhotos it prompts me to delete photos from my iPhone.  When I agree to this my photos never delete.  my iPhone is out of storage due to I can't delete photos.  What am I doing wrong?

    After loading my photos from my iphone to my mac iphoto it gives me the option to delete photos on my phone.  When I click to delete the photos do not delete from my phone.  I am out of storage due to I can not delete photos from my iphone.

    That problem is probably with your iPhone and not with iPhoto.
    But try to download again to your Mac, this time use "Image Capture" instead of iPhoto.
    Launch Image Capture from your applications folder.
    Connect your phone to a USB port.
    Select all the photos in your camera roll  to be deleted.
    Then press the "delete" key.
    If there are photos on your iPhone that have been synced with iTunes, they can only be deleted by syncing again and deselecting the albums:
    http://support.apple.com/kb/HT4236
    If even Image Capture cannot wipe your Camera Roll, you need to trouble shoot your iPhone. Try the three R's, reset, restart, restore. http://support.apple.com/kb/TS3281

  • How to delete the items in the recycle bin permanently from the windows using Diruse command

    How to delete the items in the recycle bin permanently from the windows  using Diruse command.
    Because most of the time we get out of disk space issues.
    Can somebody help me in giving with an example

    You can right-click Recycle Bin|Properties and choose radio button for
    Don't move files ....
     This one may also help.
    http://technet.microsoft.com/en-us/library/cc784980(v=ws.10).aspx
    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

  • How do i backup the list of load images automatically exceptions under Options- Content. I want to transfer to another comp without re-adding one at a time

    How do i backup the list of load images automatically exceptions under Options->Content. I want to transfer to another comp without re-adding one at a time. EVen if there is no way to backup, what is the system file for Firefox that stores these, so i can transfer this file or open it in an XML or similar editor to copy them out?

    The permissions.sqlite file stores 'allow' and 'block' exceptions for cookies, images, pop-up windows, and extensions (software) installation.
    *http://kb.mozillazine.org/Profile_folder_-_Firefox
    You can use this button to go to the Firefox profile folder:
    *Help > Troubleshooting Information > Profile Directory: Show Folder
    See also:
    *https://support.mozilla.org/kb/Recovering+important+data+from+an+old+profile
    *http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox

  • Error -11003:Menu-Fail loading Image file

    HI:
    addMenus XML File:
    <Application>
      <Menus>
        <action type="add">
          <Menu Checked="0" Enabled="1" FatherUID="43520" Image="title.bmp" Position="14" String="Menus" Type="2" UniqueID="Menus">
            <Menus>
              <action type="add">
                <Menu Checked="0" Enabled="1" FatherUID="Menus" Image="" Position="0" String="Menu_1" Type="1" UniqueID="Menu_1" />
              </action>
            </Menus>
          </Menu>
        </action>
      </Menus>
    </Application>
    when add the Image property , but continue error  Error -11003:Menu-Fail loading Image file.
    <h2>How to add images by using XML inside a B1DE project ?  </h2>
    Hope it helps
    Jimmy.l

    Hi
    在你的xml文件中,image 属性设置错误,应该填写你所加的image的绝对路径
    比如:
    <Application>
    <Menus>
    <action type="add">
    <Menu Checked="0" Enabled="0" FatherUID="43520" String="MyMenu1" Type="2" UniqueID="MyMenu1" Image="C:/MyPic.bmp">
    <Menus>
    <action type="add">
    <Menu Checked="1" Enabled="0" FatherUID="MyMenu1" String="MySub1" Type="1" UniqueID="MySub1" />
    </action>
    </Menus>
    </Menu>
    <Menu Checked="0" Enabled="1" FatherUID="43520" String="MyMenu2" Type="2" UniqueID="MyMenu2" >
    <Menus>
    <action type="add">
    <Menu Checked="0" Enabled="0" Position="0" FatherUID="MyMenu2" String="MySub21" Type="1" UniqueID="MySub21" />
    </action>
    </Menus>
    </Menu>
    </action>
    </Menus>
    </Application>

  • How to delete the saved score in a game downloaded from app store for my macbook and restart the game from the beginning ? please help

    HOW to delete the saved score in a game downloaded from the app store to restart the game from the begining with fresh scores.
    i am unable to do so. please help

    In system preferences, create a new account again, using the short name of the "deleted" account. You may be prompted to re-use the old home folder. Log out and log in to test it worked. Then log in as your new admin, and do the delete process again. Don't choose to securely delete this time - just a regular delete.
    When you have time to spare, go to Disk Utility, and use the Erase tab to securely erase free space on the drive. This will accomplish the same thing that your originally tried to do. Use the fastest method - anything more secure is a waste of time. You may need to run it overnight - it can take several hours.
    Matt

  • How can I get the resolution of an image file in JSP?

    how can I get the resolution of an image file like jpg,gif,png in JSP ?

    Hii,
    If by the resolution, u mean size..this is how u can come to know....
    String add = "path/to/some.jpeg";
    javax.swing.ImageIcon chain = new javax.swing.ImageIcon(add);
    int height = chain.getIconHeight();
    int width = chain.getIconWidth();
    Hope that helps.
    regards
                   

  • Failed to load image file-manager

    Hello everybody,
    I've recently install ArchLinux (0.6) on my machine. Then do a pacman -Sy and pacman -Su and fresh install xfree86, gnome and gnome-extra but when I run into gnome a window error appears:
    error
    Failed to load image file-manager
    Details: file not found
    I can't see mostly of the icons, like the foot of gnome in applications, the icon of file browser, the show desktop ..
    what can it be?
    well, thanks in advance.
    Ps: xscreensaver should be added as a dependency when pacman -S gnome
    Ps2: sorry my poor english

    Blaasvis wrote:i am aware, this was caused by the gtk2 update
    Yes, you're right.
    To solve (until a next release) I done:
    pacman -Rcd gtk2
    pacman -A /var/cache/pacman/pkg/gtk2-2.4.0-1.pkg.tar.gz
    And avoid to do pacman -Su ...
    Thanks and bye.

  • How to move flat file after loading in owb to other directory with othernam

    Hi All,
    I wast struck in problem . after loading the flat file in owb that file should be move or rename or zip with Date everyday .
    I dont know how to achieve this issue in owb via proceudre or any other way ... .
    how to zip files from pl/sql procedure ...... with sysdate.zip.
    any one please help me in this problem to come out soon.
    thanks ,
    murari

    One way is to use a Java stored procedure, this can then be called from a map or a process flow. The Java stored procedure will use the Zip capabilities in Java to do what you need. For example you will need the following procedure and you will have to grant privileges for your file to ZIP and the entire directory for zipping into (since the file name will be dynamic):
    For example grant YOURSCHEMA (change to your tgt schema) read on your extract directory where your file to zip is and write on your zips directory (where the zips will go);
    exec dbms_java.grant_permission('YOURSCHEMA', 'SYS:java.io.FilePermission', 'c:\staging\extracts\*','read');
    exec dbms_java.grant_permission('YOURSCHEMA', 'SYS:java.io.FilePermission', 'c:\staging\zips\*', 'write' )
    You can then create your procedure which you can invoke
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "otnZipFile"
    AS
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipOutputStream;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    public class otnZipFile
    public static void zipFile(String zip, String filename)
    byte[] buf = new byte[1024];
    try {
    String outFilename = zip;
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
    FileInputStream in = new FileInputStream(filename);
    out.putNextEntry(new ZipEntry(filename));
    int len;
    while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
    out.closeEntry();
    in.close();
    out.close();
    } catch (IOException e) {
    create or replace PROCEDURE zip_file(
    dir IN VARCHAR2,
    file_name IN VARCHAR2) IS
    LANGUAGE JAVA NAME 'otnZipFile.zipFile(java.lang.String, java.lang.String)';
    For example here I zip a file MYCSV.csv into the zip file MYZIP.zip
    exec zip_file('c:\staging\zips\MYZIP.zip', 'c:\staging\extracts\MYCSV.csv');
    Cheers
    David

  • After load .dbc file to the MAX, How to get activate the CAN signals?

    Actually, i am new to labview and have some basic concepts. I am working on the CAN signals. I want to get activate the necessary signals alone. I know how to load the .dbc file to MAX. But after loading the .DBC file to MAX, i dont know how to activate the wanted CAN signals alone. For example, if i need to activate and control the speed CAN signal alone. i am not able to activate it.
    Can anyone explain how this can be done.

    hi,
    try to download the file from the applicarion server using the dataset operations. and store in the internal table
    thanks

  • ClassLoader in JAR file not loading config file properly

    Hi all,
    I have an application that I am going to deploy using JavaWS, and everything works fine except for one little hitch. I have a configuration file, nvacconfig, located at NVAC.jar/config/nvacconfig. I'm trying to load this file into my application using a ClassLoader, but it does not seem to be working.
    I have a method from a certain class that loads the configuration file. The class is not important, as it is part of an API that I cannot alter. This class has a load(String file) method, that loads the specified configuration file with a String argument. This works fine when I run my application from the command line and when the configuration file is not located in the JAR, but I need to include this configuration file in my JAR, so I can run my app in the JWS sandbox.
    To load the file when it is NOT inside a JAR, and is simply located at config/nvacconfig, I just use:
    id.properties.load("config/nvacconfig");and it loads the configuration file, nvacconfig.
    When I include the file in my JAR and try to load it using a ClassLoader, it does not seem to work, and the load method cannot find the file. This is how I am trying to accomplish this:
    ClassLoader cl = this.getClass().getClassLoader();
    URL url = cl.getResource("config/nvacconfig");
    String file = url.toString(); //I have also tried String file = url.getFile();
    id.properties.load(file);This does not work, and I'm not sure why.
    Is there something I am doing wrong? Is this the wrong way to go about this?
    Any advice would be greatly appreciated.
    Thanks,
    Dan
    Message was edited by:
    Djaunl

    try this:
    import java.io.*;
    import java.util.jar.*;
    import java.util.zip.*;
    public class ExtractFromJAR {
         public void extractFileFromJAR(String dest, String fileName) {
              try {
                   String home = getClass().getProtectionDomain().getCodeSource().getLocation().getPath().replaceAll("%20",
                   JarFile jar = new JarFile(home);
                   ZipEntry entry = jar.getEntry(fileName);
                   File efile = new File(dest, entry.getName());
                   InputStream in = new BufferedInputStream(jar.getInputStream(entry));
                   OutputStream out = new BufferedOutputStream(new FileOutputStream(efile));
                   byte[] buffer = new byte[2048];
                   for (;;) {
                        int nBytes = in.read(buffer);
                        if (nBytes <= 0)
                             break;
                        out.write(buffer, 0, nBytes);
                   out.flush();
                   out.close();
                   in.close();
              } catch (Exception e) {
                   e.printStackTrace();
         public static void main(String args[]) {
              new ExtractFromJAR().extractFileFromJAR(".", "file.txt");
    }

  • Unable to delete file after in a file adapter

    Hello,
    I have a BPEL process , which gets invoked when there is a new .PDX file in a folder. After processing the data from the file , I want to move into the archive folder. The process moves the file properly to the archive folder, but I am unable to delete the file from the folder I read it from.
    One solution that worked was forcibly dehydrating the process using a checkpoint(). But that seems a very inefficient solution considering its expensive to do this step. Does any one else have a better solution?
    Thanks

    Just check the option "Delete after reading" in Adapter wizard if that is something you can do.. Adapter automatically deletes it once the file is moved to archive..

  • JSP page do not close after loading a file

    Hello, i am having a bit of a problem. i have the following code that help me load reports (pdf and xls) from my server in the user browser.
    What i do in my code : jsp Page 1(generationInProgress) i create one of these reports (xml with blob) --> jsp page 2(viewReport) i load the file into the page.
    My problem is pdf just go directly in the user brower but xls file(this file look like it is my page viewReport but in excel format) need to be downloaded into the user pc (work fine) but the first page (generationInProgress) stay visible.
    This is in viewReport:
    public void openFile()
    System.out.println("openFIle");
    //retrieve the report information
    String fileName = sessionBean.getReportName();
    //load the files
    File reportFile = new File(mainPathL2, fileName + "." + sessionBean.getReportFormat());
    File xslFile = new File(mainPathL2, fileName + ".xsl");
    //download file
    try
    if(reportFile == null)
    System.out.println("report file is null");
    else
    System.out.println(reportFile.length());
    //send the pdf file to screen
    HttpServletResponse response = (HttpServletResponse)facesContext.getExternalContext().getResponse();
    if(sessionBean.getReportFormat().equals("xls"))
    response.setContentType("application/vnd.ms-excel");
    else
    response.setContentType("application/pdf");
    if(reportFile.length() != 4096){
    FileInputStream fis = new FileInputStream(reportFile);
    ServletOutputStream out = response.getOutputStream();
    byte[] outputByte = new byte[(int)reportFile.length()];
    while(fis.read(outputByte) != -1)
    out.write(outputByte);
    fis.close();
    out.flush();
    out.close();
    } catch (IOException e)
    // Do your error handling thing.
    System.err.println("Download file failed: " + e.getMessage());
    e.printStackTrace();
    //delete files
    reportFile.delete();
    xslFile.delete();
    facesContext.responseComplete();
    } //end openFile() method
    Anyone can offer some help ?

    no on ever had that problem ?

Maybe you are looking for