Save into a file before exiting the program

Hi All,
I am developing a java project. It is a console application.
Initially the program loads content of a file(customer.txt) into an ArrayList.
Then it gives 3 options:-
1. Add a Customer
2. Delete a Customer
3. Save and Exit
The changes add or delete are made in the ArrayList.
The ArrayList is saved back to the customer.txt only when we select the option 3.
It works fine.
But instead of exiting the application using option 3, if we close the eclipse window or restart the computer, the changes are not saved to the file.
So could you please suggest me how we can save the changes in such situations.?

- Create a class that extends Thread
- in the run() method place the code that saves your data
- in your initialization create an instance of your Thread class but do not start it - instead register the object as a shutdown hook (use Runtime.getRuntime().addShutdownHook()).
When your application terminates the VM will kick off your thread, which should save your data. You may have to experiment a little to get it working right. Remember that only a normal termination signal will allow the VM to continue running so that it can execute your shutdown thread - a kill signal will stop the VM, as will calling Runtime.halt().
(Edit: note also that this may not work in Eclipse - I've seen problems running shutdown hooks when testing an application under Eclipse.)
Edited by: PeteFord on Nov 17, 2008 1:39 PM

Similar Messages

  • After sorting photos into albums, the albums disappeared on me. I dragged and dropped the photos and went back to check that they were in place before exiting the program. When I went back, the folder was there but no albums. Help!

    Working on an IMac - with IPhoto v.9.6 
    This is my first experience with IPhoto... trying to move files from a PC over to a Mac.
    I don't have a ton of photos but I created about 6 albums - standard albums - and dragged and dropped individual photos into each of the albums. I named each of the albums as well so I would know what was in each. After i was finished, I created a folder called 2014 and moved each of the albums into that folder. Before moving ANY of the albums, I opened each of them up to make sure that all the photos I wanted in each were indeed there - and since there were some errors on my part, I deleted any duplicates first. SO, I KNOW the photos were actually in each of the albums BEFORE i moved them into the 2014 folder.
    My intention was to then delete the photo files in my document file but once I got there I thought I would go back and double check the IPhoto file just to make sure... and the pictures were NOT in the albums where I had placed them... is there a need to save this before you move on and if so, to where and how? I was under the impression that once files were moved to albums, they remain there.
    The photos are still in the photo library but unsorted now again... I cannot even open the 2014 folder at this point.
    Thanks for any help!!

    Was back on IPhoto this morning. The folder did not open at all so I deleted it. Beside Albums, nothing showed at all. It was like I had done no work at all except to import my photo folder. Nothing was in my trash bin either.
    I started again and created one album at a time. I dragged and dropped photos into the album and exited out of IPhoto, opened up other programs and then returned to IPhoto to see if the album was still there and it was this time. I created a second album and did the same thing. This time, for some reason, the albums seem to be staying in place. I am not doing anything differently than last time. After creating three albums, I created a folder called 2014 and dragged and dropped the three albums into the folder and exited IPhoto. They were still there when I returned - YEAH! It seems to be working - for now! I am keeping my fingers crossed that my photos are not going to disappear but I am not going to delete my photo folder from my files just in case!
    Thanks for the suggestions but this may just have been a funny glitch... not sure what happened. I didn't change anything or do anything differently this time except that I am doing it one album at a time and exiting the program between creating each of them and coming back to check... very strange.

  • ITunes 9 Dumps music library when exiting the program

    I would sure appreciate any help that you all might be able to throw my way. Upgraded to iTunes 9 a couple of months ago. Basically from the time it was installed I have had the problem that I must Manually click FILE and Add Folder to Library. Upon exiting the program it will then basically dump the whole library and the next time I open iTunes I have to Add Folders to Library Again. After the upgrade to 9 I didn't even try syn'in my Nano because I was afraid I might loose music so I just left it alone and kept fiddling trying to figure out why the library would dissapear upon exiting the program.
    Just after Christmas I got a 16GB Touch so figured I really need to get the figured out..... and I'm still trying. Before connecting the Touch for the first time I COMPLETELY uninstalled iTunes, Quicktime, Apple Software UPdater, Apple Mobile Device Support, Bonjour,etc. After this, I found i still had an itunes folder in my Music folder so I deleted that (I pulled purchased music files into a seperate folder on my desktop just in case). I reinstalled itunes 9, went to File and then Add Folder to Library and imported everything. I wanted to get up and running with the Touch so I made a couple small playlists and called it a day. Exited the program, then re-opened it just to check if it was still there and it was! I was excited..... but not for long. Next day opened iTunes 9 and there was no music, the library was empty.
    I could go on and on... but won't. I've read posts about checking the XML file in wordpad, which I've done and seems like it's correct. even when I go to Preferences/Advanced, and look at where it's storing it seems correct.
    Can some one point me where to look?????
    Thx! Jeromy

    Thank you so much for your reply Katrina. Interesting stuff. Somehow in the mega searches I was doing for answers I didn't think to search using the Vaio angle. I will definitely go through those Vaio Files. This is my 4th Vaio and I NEVER seem to use any of the preloaded software, but to this point have not had problems until I installed iTunes 9.
    Last night I read another post that reminded me that the music files that show up in the iTunes/music folder are just "pointers" or say "shortcuts" (I can't remember the actual term used) to where the ACTUAL music files are located. When I used the Add Folders from the file menu I've always assumed that these "shortcuts" have been placed in the iTunes/Music folder properly. But just in case, I clicked on the Copy Files to iTunes Media folder in Advanced tab to be safe and then I did the Drag/Drop from my windows MY MUSIC folder (rather than using the Add Folders to Library in iTunes). I started by dragging and dropping like 5 albums. Then I'd close, open, close, open etc. to see if they would stay in my iTunes music library.... and they DID! So I left it overnight and then this morning I dragged a bunch more albums into my iTunes music library. Did another close, open, close, open on iTunes and so far everything is staying in place. My next test is going to be to completely shut down my Vaio and start it back up and see if it's all still there.
    Do you think any of this makes sense, or relates back to the Vaio software issues from the post you provided? I don't quite understand why it would work to drag/drop but not simply click Add Folders to Library???
    Thanks Again,
    Jeromy

  • I have PS 6 and just purchased an iMac and am running OS 10.10.1 (Yosemite).  When i try to Save or Save As a file I get the following message:  Could not save as "Whatever.psd" because this file is locked, you do not have necessary access permissions, or

    I have PS 6 and just purchased an iMac and am running OS 10.10.1 (Yosemite).  When i try to Save or Save As a file I get the following message:  Could not save as "Whatever.psd" because this file is locked, you do not have necessary access permissions, or another program is using the file.  Use the Get Info command in the Finder to ensure the file is unlocked and you have permission to access the file.  If the problem persists, save the document to a different file or duplicate it in the Finder.  Any suggestions?  Thanks.

    Photoshop: Basic Troubleshooting steps to fix most issues
    Look under Troubleshoot User Permissions.
    Gene

  • I am trying to install software for iTwin Connect, but after downloading the dmg file and launching the program, I receive a message saying the file can't open and to check my internet connection.  Any ideas?

    I am trying to install software for iTwin Connect, but after downloading the dmg file and launching the program, I receive a message saying the file can't open and to check my internet connection.  Any ideas?

    Many Thanks, Kurt.
    I knew I'd seen the solution you've provided somewhere - either in MacWorld or MacFormat - but couldn't remember the Gatekeeper bit!
    I shall save it somewhere VERY safe now in case this happens again …
    You have made an old man very happy and saved me from worrying that senile decay had suddenly set in. (I was 70 last week so you might understand the situation from that.)
    Best wishes
    OllyanDinah

  • Can I back up the files before doing the recovery?

    Hello
    If using the recovery disk to load windows (I have Windows Vista 32-bit) is it possible to save files (pictures, etc...) before wiping out these files on the hard drive?
    I have not backed up some files and cannot access windows to do this now...am wondering if I can back up the files before doing the recovery?
    Any help would be appreciated : )

    Hello
    You can try to start Vista in Safe mode. Start your notebook and press F8. Choose option to start OS in safe mode. When Vista starts connect external HDD or USB memory stick and copy all your data there.
    I have done this three weeks ago. I was not able to start Vista properly due to blue screen.

  • Hi when i use treeMap class and if i exit the program

    hi
    hi when i use treeMap class and if i exit the program,
    what will happen? the information that i put in the treeMap will be disappear??
    if it is like that,,how am i able to retrieve my data...when i restart my program..
    once i put ID as key and put my customer information,
    in it, after exit my program,, and i can't find
    my customers by their ID,,,,,,,,,how can,,i solve it......

    what will happen? the information that i put in the
    treeMap will be disappear??Yes. Of course. If you want data to hang around you have to tell the computer. If you want anything to happen you have to tell the computer.
    if it is like that,,how am i able to retrieve my
    data...when i restart my program..Tada! Tell the computer. Your simplest option is to use Serialization.
    Before exiting your program, serialize your TreeMap to disk. After starting your program serialize your TreeMap from disk.
    First stop should be your text book to learn what Serialization is and how it works, then try to write some code, then ask us to help with any problems.
    Dave.

  • When i click on an excel or word file in 2007 the program begins to open but then an error message says There was a problem sending the command to the program

    when i click on an excel or word file in 2007 the program begins to open but then an error message says There was a problem sending the command to the program.
    i am using office2007  with windows7 premium home edition.  i have checked file associations., all DDE settings. i have even tried this in safe mode. the same thing happens. please note once i see the error. i can then go back to the file click on
    it a second time and it WILL open. AND i can open any file if i open excel and and find the file from there. i uninstalled and re-installed office 2007 from scratch. And i checked the compatibility mode (all un-checked) still the problem persisits. this is
    a real PITA.   anyone have any solution for this? Thanks 
    ken yanow

    Hi,
    Have you try to un-select the Ignore other applications that use Dynamic Data Exchange (DDE) setting?
    Click the Microsoft Office Button, and then click Excel Options.
    Click Advanced, and then click to clear the Ignore other applications that use Dynamic Data Exchange (DDE)
    check box in the General area.
    Click OK.
    If the problem cannot resolve, the Run as administrator may selected.
    Go to Office default install location: C:\Program Files\Microsoft Office\Office12.
    Right-click EXCEL.EXE > Properties >
    Compatibility tab.
    Under Privilege Level, uncheck Run this program as an administrator
    check box.
    Best regards.
    William Zhou
    TechNet Community Support

  • In Snow Leopard, there was a quick look feature that allowed you to look at files without opening the program.  It doesn't show up in Lion on my iMac.  Any ideas?  Thanks

    In Snow Leopard, there was a quick look feature that allowed you to look at files without opening the program.  It doesn't show up in Lion on my iMac.  Any ideas?  Thanks

    While in Finder, select the file (click on its icon once) then press the Spacebar.

  • How can I make a droplet save a modified file next to the original file?

    I am having a problem getting a Photoshop Droplet save a modified file next to the original file. That is, when I drag a file "page_6.pdf" from some directory onto my droplet, I want it to do its work and save a modified "page_6.psd" in that same directory.
    This isn't working for me on Photoshop CC 2014 on Mac OS 10.10.
    I have an Action which has an Open command, with the filename "page_1.pdf". Then it has a bunch of editing commands. Then it has a "Save As... Photoshop format" command, and a Close command. When I run this action within Photoshop, it brings up Open and Save As dialogues, and works fine.
    In creating the droplet, I used File... Automate... Create Droplet..., and selected the following options:
    Override Action "Open" commands
    Destination menu value = Folder
    Using Choose... button, select an output folder, Directory_1/ .
    Check Override Action "Save As Commands" is checked
    For File Naming, I use [Document Name] + "_deleteme" + [extension]
    When I drag a folder, say "page_5.pdf" from some directory onto the droplet, Photoshop runs the Action on the document. However, it saves the modified document in Directory_1/, regardless of where the original file came from. And it always names the modified document "page_1_deleteme.psd", instead of using the Document Name of the original file.
    If I modify the Open command in the Action to mention a different file, then the droplet always names the modified document with that name. It's as if Document Name in the File Naming dialogue always reflects what's in the Open command in the Action.  But -- I asked the droplet to Override Action "Open" commands!
    When I set the Destination menu value to "Save and Close", then when I drag a file onto the droplet, the droplet opens a File Save dialogue and forces me to tell it where to store the file.  I don't understand this behaviour, and have a hard time reconciling it with the documentation at Photoshop Help | Processing a batch of files .
    (Interestingly, when Destination menu value = None or Save and Close, Photoshop displays an alert about overwriting an existing droplet when I click OK to save. But when Destination menu value = Folder, there is no alert about overwriting existing droplet.)
    How can I set up a droplet so that it writes the modified file in the same directory as the original file, and with the same root filename, but a different extension to reflect the different output file format?
    Has anyone else made a droplet behave this way on Photoshop CC 2014 on Mac OS X 10.10?
    Thanks in advance for your help.

    Thanks for your insights.
    Does my Action need to include an Open command?  I sure thought so, because of how the Photoshop Help | Processing a batch of files documentation describes 'Override Action “Open” Commands'.
    "...If the action contains an Open command that opens a saved file and you don't select this option, the Batch command opens and processes only the file you used to record the Open command..." I don't want to operate only the file I used to record the Open command. However, this sentence doesn't say that an Open command should be part of a droplet Action.
    "...Deselect this option if the action was recorded to operate on an open file..."  Maybe I if I rethink my Action as operating on an open file, then the Droplet will take care of the Open for me.  However, I have less control over the options the droplet's Open command uses.
    I'll try disabling the Open command, and create a Droplet with that.

  • Good afternoon ladies and gentlemen!   My question concerns the impossibility to open RAW-files directly from the program Adobe Bridge. At the moment when you open a RAW-file from Adobe Bridge by double-clicking, RAW-file is opened only in Photoshop. In t

    Good afternoon ladies and gentlemen!
    My question concerns the impossibility to open RAW-files directly from the program Adobe Bridge. At the moment when you open a RAW-file from Adobe Bridge by double-clicking, RAW-file is opened only in Photoshop. In the settings Adobe Bridge - in "open RAW-files by double-clicking in Adobe Camera Raw» box is checked. When you try any changes in the settings Adobe Bridge system displays a message:
    Bridge's parent application is not active. Bridge requires that a qualifying product has been launched at least once to enable this feature.
    The entire line of Adobe products on my computer updated to the latest updates. Previously, a family of products Adobe Photoshop on your computer is not set. Computer - PC, Windows 7 Enterprises.

    <moved from Adobe Creative Cloud to Bridge General Discussion>

  • My safari screen suddenly fills my entire screen, and there is no right hand corner button to push to manually shrink it. What to do? I can never even exit the program without quitting it.

    My screen when I am using Safari suddenly fills my entire screen, and there is no right hand corner button to push to manually shrink it. What to do? I can never even exit the program without quitting it.This has happened only within the last two days.

    Try changing the screen resolution.
    Go to Apple Menu / System Preferences / Displays.
    Change the resolution. Whatever numbers are shown, e.g. 1280 x 960, select a larger one. The larger the number, in the resolution the smaller the display on the screen. You can keep changing this till you find the resolution that suits you.

  • Do I have to save each pdf file before printing?

    Do I have to save each pdf file before printing? It won't allow me to print unless I save it first.

    Are you viewing in a browser? Which one? What steps are you taking to print and exactly what happens?

  • How to exit the program using AS3??

    Hi guys  , i'm trying to use a button to exit the program. anyone knows which code to use?

    What exactly do you mean by 'exit the program'? What program? Is your Flash Object in a browser, or is it an AIR app?
    If you're talking about an AIR app, have a look at:
    NativeWindow.close()

  • FAQ: When I apply edits to an image using Revel, does it save a new file or just the edits?

    Q. When I apply edits to an image using Revel, does it save a new file or just the edits?
    A. Revel cloud keeps a copy of your full resolution originals. Edits in  revel are non-destructive, so your original is always preserved (unedited). When you export photo (MAC) Save to Camera Roll (iOS), that's when Revel applies your edits. On iOS the preview is used. on MAC the full resolution of the original is used to generate the new edited photo.

    Thanks kumars ,
    I have a specific drag and drop area on our website. This works fine for all earlier releases of Firefox after these security settings
    "(1) Enter "about:config" in the URL field; (2) Right click and select New->Boolean; (3) Enter "signed.applets.codebase_principal_support" (without the quotes) as a new preference name; (4) Click OK and try loading the file again."
    Bust these settings not work for me in Firefox 17.
    Yes the drag and drop functionality is java script based and i am not using any script blocker addons.

Maybe you are looking for

  • Tax Calculation of free goods

    Hi We have a requirement where the client wants only VAT to be posted in GL accounts and not the price.For this I tried free goods condition type R100 with AltCBV 28.But the VAT value is also coming zero. I want the VAT to be calculated on Pricing co

  • How to know no of pages in smart forms to be printed ?

    Hi,      How to know no of pages in smart forms to be printed ? though i got SFSY structure during run time of smartform , even that was not useful. &SFSY-FORMPAGES& Displays the total number of pages for the currently processed form. This  allows yo

  • Problem with jdk1.3 and WLS5.1.0

    I have a problem a when I start WLS5.1.0 with jdk1.3.0 I get AccessControlException when I try to create connection pool. <WebLogicServer> Failed to invoke startup class weblogic.jdbc.common.internal.JdbcStartup=weblogic.jdbc.common.inte rnal.JdbcSta

  • PowerView - scatter plot with an Equation of the line

    Hi guys --here is what I'm trying to accomplish in either powerview or powerpivot : i) a 3d scatterplot, ii) with the axis driven by the data model, iii) with the equation of the line (polynimial, log, power etc) adjusting dynamically.  I can find pi

  • Default Text in Purchase Info Record

    Hi All, I am facing one problem during the PIR maintainance. While creating PIR for some plants in the Purchase Order Text some default value is coming. Is there any way to check where we are maintaining the default value for plant specific. Regards