File.delete() and File.deleteOnExit() doesn't work consistently..

I am seeing some odd behavior with trying to delete files that were opened. Usually just doing new File("file.txt").delete() would work. However, in this case, I have created an input stream to the file, read it in, saved it to another location (copied it), and now I am trying to delete it.
The odd thing is, in my simple application, the user can work with one file at a time, but I move "processed" files to a lower pane in a swing app. When they exit it, it then archives all the files in that lower pane. Usually every file but the last one opened deletes. However, I have seen odd behavior where by some files don't delete, sometimes all of them wont delete. I tried the deleteOnExit() call which to me should be done by the JVM after it has released all objects such that they don't matter and the JVM ignores any object refs and directly makes a call (through JNI perhaps) to the underlying OS to delete the file. This doesn't work either.
I am at a loss as to why sometimes some files delete, and other times they don't. In my processing code, I always close the input stream and set its variable to null. So I am not sure how it is possible a reference could still be held to the object representing the file on disk.

and then, in the other class
  public int cdplayerINIToMMCD(File aDatabase, String thePassword) throws IllegalArgumentException {
     /*---------DATA---------*/
     String dbLogin, dbPassword;
     JFileChooser fc;
     INIFileFilter ff;
     int dialogReturnVal;
     String nameChosen;
     File INIFile;
     ProgressMonitor progressMonitor;
     BufferedReader inFileStream;
     String oneLine;
     int totalLines = 0;
     int linesParsed = 0;
     boolean openDBResult;
     int hasPassword;
     if ((aDatabase == null) || (!aDatabase.exists()) ||
        (FileManagement.verifyMMCD(aDatabase) == FileManagement.VERIFY_FAILED)) {
        throw new IllegalArgumentException();       
     else { 
        currentDB = aDatabase;
        if(thePassword == null) {
          dbPassword = "";
        else { dbPassword = thePassword; }
        dbLogin = dbPassword; //For MSAccess dbLogin == dbPassword
     //Ask the user for the cdplayer.ini file.
     //Create a file chooser
     if (System.getProperty("os.name").indexOf("Windows") > -1) {
        fc = new JFileChooser("C:\\Windows");
     else {
        fc = new JFileChooser();     
     fc.setMultiSelectionEnabled(false);
     fc.setDragEnabled(false);
     //Create a new FileFilter
     ff = new INIFileFilter();
     //Add this filter to our File chooser.
     fc.addChoosableFileFilter(ff);
     fc.setFileFilter(ff);
     //Ask the user to locate it.
     do {
        dialogReturnVal = fc.showOpenDialog(mainFrame);
        if (dialogReturnVal == JFileChooser.APPROVE_OPTION) {
           nameChosen = fc.getSelectedFile().getAbsolutePath();
           if(nameChosen.toLowerCase().endsWith(INIFileFilter.FILE_TYPE)) { INIFile=new File(nameChosen); }
           else { INIFile = new File(nameChosen+INIFileFilter.FILE_TYPE); }
           if (!INIFile.exists()) {
              continue; //If the name specified does not exist, ask again.
           else { break; }
        else { //User clicked cancel in the open dialog.
           //Ignore what we've done so far.
           return(IMPORT_ABORTED);
     } while(true); //Keep asking until cancelled or a valid file is specified.
     //Determine how many lines will be parsed.
     try {
       //Open the INI for counting
       inFileStream = new BufferedReader(new InputStreamReader(new FileInputStream(INIFile)));
       while ((inFileStream.readLine()) != null) {
           totalLines++;
       //Close the INI file.
       inFileStream.close();
     } catch (IOException ex) { return(IMPORT_FAILED); }
     //Make a progress monitor that will show progress while importing.
     progressMonitor = new ProgressMonitor(mainFrame, "Importing file","", 0, totalLines);
     progressMonitor.setProgress(0);
     progressMonitor.setMillisToPopup(100);
     progressMonitor.setMillisToDecideToPopup(1);
     //Make our DatabaseHandler to insert results to the database.
     dbh = new DatabaseHandler();
     //Open the database connection.
     do {
       try {
          openDBResult = dbh.openDBConnection(currentDB, dbLogin, dbPassword);
       } catch(JDBCException ex) { return(IMPORT_JDBC_ERROR); } //OUCH! can't write anything.
         catch(SQLException ex) {
             openDBResult = DatabaseHandler.OPNCN_FAILED;
             //Can not open the database. Is it password protected?
             hasPassword = JOptionPane.showConfirmDialog(mainFrame, "Could not open the database. "+
                                            "The password is wrong or you have not specified it.\n"+
                       "Do you want to enter one now?", "New password?", JOptionPane.YES_NO_OPTION);
            if (hasPassword == MMCDCatalog.DLG_OPTN_YES) {
               dbPassword = JOptionPane.showInputDialog(mainFrame, "Please enter your "+
                                                          "password for the DataBase:");
                dbLogin = dbPassword; //For MSAccess, login == password                                                    
            //If the password wasn't the problem, then we can't help it.
            else { return(IMPORT_FAILED); }
     } while(openDBResult != DatabaseHandler.OPNCN_OK); //If it is OK, no exception thrown.
     //Import the ini file
     try {
        //Open the INI file for parsing.
        inFileStream = new BufferedReader(new InputStreamReader(new FileInputStream(INIFile)));
        //Read and parse the INI file. Save entries once parsed.
        while ((oneLine = inFileStream.readLine()) != null) {
           parseLine(oneLine);
           linesParsed++;
           progressMonitor.setNote("Entries imported so far: "+entriesImported);
           progressMonitor.setProgress(linesParsed);
           if ((progressMonitor.isCanceled()) || (linesParsed == progressMonitor.getMaximum())) {
              progressMonitor.close();
              break;
        //Close the INI file.
        inFileStream.close();
     } catch (IOException ex) {
          //Make absolutely sure the progressMonitor has disappeared
            progressMonitor.close();
            if (dbh.closeDBConnection() != DatabaseHandler.CLSCN_OK) {
             JOptionPane.showMessageDialog(mainFrame, "Error while reading the INI file.\n"+
                "Error while attempting to close the database", "Error", JOptionPane.INFORMATION_MESSAGE);
          else {
             JOptionPane.showMessageDialog(mainFrame, "Error while reading the INI file.",
                                                "Error", JOptionPane.INFORMATION_MESSAGE);     
            return(IMPORT_FAILED);
     //Make absolutely sure the progressMonitor has disappeared
     progressMonitor.close();
     //Close the database connection
     if (dbh.closeDBConnection() != DatabaseHandler.CLSCN_OK) {
        JOptionPane.showMessageDialog(mainFrame, "Error while closing the database after import.",
                                      "Error", JOptionPane.INFORMATION_MESSAGE);
     //Did the user cancel?
     if (totalLines != linesParsed) {
        return(IMPORT_ABORTED);     
     //Success!
     //Everything ok. Return the number of entries imported.
     return(entriesImported);
  }

Similar Messages

  • Okay, i have 2 bugs with maverick.  First, when I delete a file within a window, the files deletes but the preview doesn't delete until I close the window and reopen it.  Second, I work on a network of computers and the search feature is now buggy...

    Okay, i have 2 bugs with maverick.  First, when I delete a file within a window, the files deletes but the preview doesn't delete until I close the window and reopen it.  Second, I work on a network of computers and the search feature is now buggy...  When I search for a file, A) it asks me if it's a name, or it wont produce anything, and B), its slower than in prior OS versions and in some instances I have to toggle to a different directory and go back to my original directory in the search: menu bar or the search wont produce anything...  Very buggy. 

    It appears to me that network file access is buggy in Maverick.
    In my case I have a USB Drive attached to airport extreme (new model) and when I open folders on that drive they all appear empty. If I right click and I select get info after a few minutes! I get a list of the content.
    It makes impossible navigate a directory tree.
    File access has been trashed in Maverick.
    They have improved (read broken) Finder. I need to manage a way to downgrade to Lion again.

  • Files deleted from the Library and now internet doesn't work?

    Hello,
    I'm new here and this is probably going to sound dumb but... my father deleted some files from the Library by mistake and now internet doesn't work in his computer. Everything seems normal, but the webpages don't load (we tried lots of pages and 3 browsers). If you try to update any software it can't connect to the internet either.
    He reinstalled the system (it's Mountain Lion, I think) but it didn't worked (it was a partial reinstallation, without losing the data). He also tried restarting and pressing CMD-R but nothing happened.
    Any ideas on how to solve this problem? Thank you so much in advance! (and sorry for any typos, English is not my native language)

    Hello Eleone, & a warm Welcome!
    So what exactly isn't working or any messages you get?
    Does Mail still work?
    Might try this...
    Make a New Location, Using network locations in Mac OS X ...
    http://support.apple.com/kb/HT2712
    10.5, 10.6, 10.7 & 10.8…
    System Preferences>Network, top of window>Locations>Edit Locations, little plus icon, give it a name.
    10.5.x/10.6.x/10.7.x/10.8.x instructions...
    System Preferences>Network, click on the little gear at the bottom next to the + & - icons, (unlock lock first if locked), choose Set Service Order.
    The interface that connects to the Internet should be dragged to the top of the list.
    If using Wifi/Airport...
    Instead of joining your Network from the list, click the WiFi icon at the top, and click join other network. Fill in everything as needed.
    For 10.5/10.6/10.7/10.8, System Preferences>Network, unlock the lock if need be, highlight the Interface you use to connect to Internet, click on the advanced button, click on the DNS tab, click on the little plus icon, then add these numbers...
    208.67.222.222
    208.67.220.220
    (There may be better or faster DNS numbers in your area, but these should be a good test).
    Click OK.

  • I upgraded to Lion and now can't print PDF files and Acrobat reader doesn't work anymore. What can I do to get it working?

    I upgraded to Lion and now can't print PDF files and Acrobat reader doesn't work anymore. What can I do to get it working?

    If you upgraded and were using a version of Acrobat Reader that was legacy, that is PPC compatible, then you will have to upgrade to a version compatible with Lion as Lion no longer has Rosetta to interface with the legacy software.
    I know that Acrobat, full version, 10 works with Lion...use it myself.

  • In my iTunes on the iPad I've got 95 items that are stuck and I tried swiping them to delete them but it doesn't work dose any one know how to empty the download tab

    In my iTunes on the iPad I've got 95 things that are stuck and I tried swiping them to delete them but it doesn't work dose any one know how to empty the download tab

    Thanks, but, using the "free" version of Reader, there is no opportunity to open nor import the xml data - the menu options do not exist - there is no import listed.
    If we try to open the xml file directly, then we get an error - something to the effect of "unsupported file type, or the file is corrupted".
    I just noticed in my Pro version that there is the command File ->Form Data ->Import Data to Form... command. Is this what you are referring to?
    What do you recommend? Perhaps the easiest thing to do would be to purchase a few copies of Acrobat Pro for the reservations people to use? I was hoping that the free version of reader would do it, but perhaps not?
    Thanks again,
    Rob

  • I just recently upgraded my itouch from 4.1 to ios5, and updated to itunes 10.5. when isynced my music files,ebooks and other apps, all is working except when im trying to sync my video files. it says, canot be synced as cannot be played on this ipod.help

    i just recently upgraded my itouch from 4.1 to ios 5, and updated to itunes 10.5. but when i synced my music files,ebooks and other apps, all is working except when im trying to sync my video files. it says, canot be synced as cannot be played on this ipod. but those are the same files that i have when i was using the old 4.1 version and its syncing just fine.. the itunes advanced tab "create iphone or ipod version" is not working either so i cant convert it to be xferred and synced. what can i do to have my video files synced?

    i had the same problem but i just got a new video converter and made it convert videos to ipod/iphone format and then put them into itunes. i would suggest GOM encoder as the encoder can convert them and then once they're finished converting, put them automatically into your itunes for you. from there you can just sync them to your ipod.

  • HT1766 I cannot backup my iphone, it keeps telling me the backup is corrupt and not compatible. All forums have suggested I delete the last backup but that was months ago and I'm afraid if I do that and it still doesn't work, I won't have anything saved

    I cannot backup my iphone, it keeps telling me the backup is corrupt and not compatible. All forums have suggested I delete the last backup but that was months ago and I'm afraid if I do that and it still doesn't work, I won't have anything saved. Can anyone help?

    Try to connect in recovery mode, explained in this article:
    iOS: Unable to update or restore
    Before that, back up your device, explained here:
    iOS: Back up and restore your iOS device with iCloud or iTunes
    How to back up your data and set up as a new device
    You can check your warranty status here:
    https://selfsolve.apple.com/agreementWarrantyDynamic.do

  • When i open iTunes U it comes up with just the brown bookshelf but no icons to click on and then it closes. I've deleted it and then re-download it and it still doesn't work.

    On the bookshelf there's no icons to click on and after a mintue it closes. I've deleted it and then re-download it and it still doesn't work. Im using a ipod touch 4 and im on 5.1.

    I, too, am having this problem and it's annoying.  The app just shuts down every time I use it. Too bad cuz it looks lie there are so many wonderful courses in the catalog.
    Any tips on how to fix this would be appreciated!
    Thanks.

  • My Windows part of the drive got all of the files deleted and got renamed

    My Windows part of the drive got all of the files deleted and got renamed to Time Machine Backups. This all happened when i woke up and i tried to do to the windows part of the drive and it was not there. So I went to the mac part and i saw it was renamed to Time Machine Backups. So then I clicked to see if any thing was in the part. Nothing. I tried to go to boot camp assistant it said -The startup disk cannot be partitioned or restored to a single partition. The startup disk must be formatted as a single Mac OS Extended (Journaled) volume or already partitioned by Boot Camp Assistant for installing Windows.-So Then I went to disk utility to erase it but it did nothing. PLEASE HELP ME

    1. Time machine probably has the disk locked. Go into time machine preferences and turn it off.
    2. open DU (disk utility), see if you can dismount the boot camp partition. If not, log out, log back in and try again with DU. Once it will mount and dismount go to step 3.
    3. In DU select the boot camp volume, select erase, select msdos file system (format), select name for partition, select erase.
    4. Close DU, Open preferences > system > startup disk.
    5. Highlight the msdos partition, close preferences (this blesses the msdos partition and sets it to boot).
    6. Place your windows cd/dvd in the tray, close tray and reboot.
    7. Install windows.
    8. After complete installation, select run, type in "cmd" (in windows).
    9. A windows terminal will open, at the prompt type:
    convert c: /fs:ntfs
    press enter, it will ask if you want to schedule the conversion at the next startup?.
    10. Select yes. Time machine will leave a ntfs drive alone, simply because it cannot write to it.
    11. Reboot windows and let it convert the file system. That's it.
    Kj

  • When I updated Facebook 6.7.0, It didyn't complete the updating and my Facebook doesn't work so I deleted it. What can I do now to downgrade  it ?

    when I updated Facebook 6.7.0, It didyn't complete the updating and my Facebook doesn't work so I deleted it. What can I do now to downgrade  it ?

    If recovery mode did not work, try DFU mode, but don't use the latest backup to restore from after you have set it up "as new ipod" again.
    DFU mode

  • I am trying to download a file from Safari. It doesn't work.

    I am trying to download a file from Safari. It doesn't work. It always comes up with a notification saying, 'Safari could not download this file'. Why does it do that? More importantly, what should I do? how do I download it?
    Thanks to the users who reply to this. It will help me a lot.

    What type of file is it?
    If safari can't natively open the file, or there is no App installed thatr can, it won't download.

  • When I upgrade to Snow Leopard/Lion - after installing it are my files deleted and my preferences changed?, When I upgrade to Snow Leopard/Lion - after installing it are my files deleted and my preferences changed?

    When I upgrade to Snow Leopard/Lion - after installing it are my files deleted and my preferences changed?, When I upgrade to Snow Leopard/Lion - after installing it are my files deleted and my preferences changed?

    If you install those new OS X versions over the top of what you already have, your files and preferences should remain.  However, it's a very good idea to have at least one complete backup of your Mac's disk before you try anything like that.

  • I imported videos from photo into iMovie when I set up iMovie (obvious mistake) and now iMovie doesn't work properly, nor can I move specific videos into a folder where I want them. How do I fix this?

    I imported videos from photo into iMovie when I set up iMovie (obvious mistake) and now iMovie doesn't work properly, nor can I move specific videos into a folder where I want them. How do I fix this? I even tried deleting iMovie, bought a new copy and installed it, but the folder "iPhoto Videos" is still there and I can't get new clips loaded to iMovie, especially where I want them. Please help.

    The iPhoto Videos do occasionally have problems. I've seen a lot of people write messages to this Discussion group describing similar problems. The only thing that seems to get around this problem is to pull the video clips out of iPhoto then import them directly into iMovie. Once the troubles with iPhoto Videos starts, I haven't yet seen anyone write back with something that they did to fix it.
    The most difficult part of doing this is the movies in iPhoto might be a little difficult to track down. But you can create a smart alum that does that for you. Go to iPhoto > File Menu > New Smart Album:
    Set the first pulldown menu to keyword, second to contains, then in the last box type Movie with a capital 'M'. Then click OK. This smart album more or less does as search of the whole iPhoto Library and only displays items that match your search tearm of "Movie" exactly. In that smart album then you can find the original Movies you want to move out of iPhoto and into iMovie, <CTRL> click on the Movie clip, then choose Reveal in Finder. That will jump you out of iPhoto temporarily and into the iPhoto Library folder. From there you can move that movie file to the desktop. Move all the clips you want, once they're all collected up go to iMovie and go to the File Menu > Import Files. Then point it to the desktop where you moved your video clips.
    This will put all those videos into an Event folder in iMovie and bypass iPhoto Videos altogether.

  • I clicked "yes" to upgrade iTunes and now it doesn't work. I get an error message stating my computer is missing MSVCR80 and then a message stating Error 7 (Windows Error 126). I've tried reloading iTunes twice. What can I do?

    I clicked "yes" to upgrade iTunes and now it doesn't work. I get an error message stating my computer is missing MSVCR80 and then a message stating Error 7 (Windows Error 126). I've tried reloading iTunes twice. What can I do?

    Go to Control Panel > Add or Remove Programs (Win XP) or Programs and Features (later)
    Remove all of these items in the following order:
    iTunes
    Apple Software Update
    Apple Mobile Device Support (if this won't uninstall move on to the next item)
    Bonjour
    Apple Application Support
    Reboot, download iTunes, then reinstall, either using an account with administrative rights, or right-clicking the downloaded installer and selecting Run as Administrator.
    The uninstall and reinstall process will preserve your iTunes library and settings, but ideally you would back up the library and your other important personal documents and data on a regular basis. See this user tip for a suggested technique.
    Please note:
    Some users may need to follow all the steps in whichever of the following support documents applies to their system. These include some additional manual file and folder deletions not mentioned above.
    HT1925: Removing and Reinstalling iTunes for Windows XP
    HT1923: Removing and reinstalling iTunes for Windows Vista, Windows 7, or Windows 8
    tt2

  • How do I restore column headings in Response table after accidently deleting them? Undo doesn't work.

    How do I restore column headings in Response table after accidently deleting them? Undo doesn't work (only seems to go back one level). I also have so many headings I won't be able to type them in manually!

    With the help of information from user, ptressel, in [https://support.mozilla.org/en-US/questions/1032154#answer-673322 a post here about the existence of sessionstore.js when version 33 was released], I was able to easily recover my tabs and tab groups as follows:
    # close Firefox and, perhaps, allow a few seconds (30s?) for any final closing of files;
    # check to see if you have a sessionstore.js file in your profile folder, named like the one I documented in my original post above;
    # if it is not timestamped prior to the discovery of your problem, open the sessionstore-backups folder;
    # check if the recovery.js file is suitably timestamped and, if not, the recovery.bak.
    # At this point, you are likely to find that none of them are prior to your problem occuring. If so, open your backups of this folder and go through steps 2-4 to find a file prior to your problem occuring.
    # When you find a file, copy it to the root of your current profile folder and name it, "sessionstore.js"
    # Open Firefox. Mine opened up as desired.
    This is a Windows solution. Sorry I can't comment on other platforms, but I'd bet that as this is just a file copy and renaming, it is likely the same.
    For Windows users, you may find you need to sign out and login as an administrator in order to access the backups. You need not logoff your standard account, but do have Firefox closed as described above.
    Hope that helps.

Maybe you are looking for

  • Showing column value as counter in sql query - report

    I created a classic report with search bar based on an sql query. I would like to show the "notes" column in this query using some sort of counter and as a hyperlink to another section on the page (same idea as footnotes in a book). So if I have 10 r

  • IPod Touch 5th Gen. Not Charging!

    Hello darlings, ill just cut to the chase with what i need help with! My ipod touch 5th generation, which ive had for nearly 4 months now no longer charges! When i plug it into a wall socket it doesnt charge, when i plug it into my laptop it doesnt c

  • WM relevant ....Outbound delivery (without reference) VL01NO

    Hi , I have created a delivery with Delivery Type WGO using T code VL01NO .... but in the picking tab of outbound delivery , it is neither showing me warehouse number nor OverAllWMStatus ( status is NOT relevant). The material is available in warehou

  • ADF BC Binds too many parameters

    This has to be something simple. There's only one bind parameter (nullable), and one View criteria...but for some reason, ADF BC wants to bind 3 parms and it blows up. Anyone have any insight as to where the 3rd is coming from? [665] ViewObjectImpl.c

  • Can I use an Mac Mini without a monitor?

    I'm using a Mac specifically to develop a mobile app, and the intention was that once everything was set up, I could just TeamViewer in to take control without needing a monitor. This works fine with a monitor plugged in, but when I disconnect the mo