How to close ImageIcon file

Discussion in 'Java' started by Phil..., Oct 9, 2003.

  1. Phil...

    Phil... Guest

    I have a directory that has lots of jpg and gif files.
    I want to delete all of the small ones, those with
    height or width less than 100 px.
    I use close to the following code to get the height and width.

    File dir = new File(".");
    String files[] = dir.list();
    ImageIcon myimage = new ImageIcon(files);
    int height = myimage.getIconHeight();
    int width = myimage.getIconWidth();

    At this point, File.delete() returns false
    most of the time. My guess is that the file
    is still open. How can I close it so I can delete it?
    N.B. File.deleteOnExit() works fine.

    Tnx, phil...
     
    Phil..., Oct 9, 2003
    #1
    1. Advertising

  2. "Phil..." <> wrote in message news:D03hb.717481$uu5.118293@sccrnsc04...
    I have a directory that has lots of jpg and gif files.
    I want to delete all of the small ones, those with
    height or width less than 100 px.
    I use close to the following code to get the height and width.

    File dir = new File(".");
    String files[] = dir.list();
    ImageIcon myimage = new ImageIcon(files);
    int height = myimage.getIconHeight();
    int width = myimage.getIconWidth();

    At this point, File.delete() returns false
    most of the time. My guess is that the file
    is still open. How can I close it so I can delete it?
    N.B. File.deleteOnExit() works fine.

    When you load an image that way, a separate Thread is started to load the file.
    Your result varies because sometimes the file is still being loaded.
    Look at the JavaDocs for ImageIcon - the getImageLoadStatus in particular.
    You can't reliably look at the height and width before the image is loaded.

    Bill
     
    William Brogden, Oct 9, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. terry

    JTable ImageIcon

    terry, Aug 5, 2003, in forum: Java
    Replies:
    2
    Views:
    4,077
    Roedy Green
    Aug 6, 2003
  2. Cheok Yan Cheng

    ImageIcon.paintIcon wont work in JApplet

    Cheok Yan Cheng, Aug 13, 2003, in forum: Java
    Replies:
    0
    Views:
    1,759
    Cheok Yan Cheng
    Aug 13, 2003
  3. tiewknvc9

    ImageIcon to Image in a jar file?

    tiewknvc9, Aug 14, 2006, in forum: Java
    Replies:
    3
    Views:
    1,094
  4. Replies:
    13
    Views:
    1,125
    RedGrittyBrick
    Jan 17, 2007
  5. Iñaki Baz Castillo
    Replies:
    7
    Views:
    874
    Iñaki Baz Castillo
    Jan 12, 2010
Loading...

Share This Page