Error message when saving to a:\ drive when no disk present

I am using a Jfilechooser andsaving images using ImageIO, but I want add in the code necessary to display an error message when the user tries to save to the a:\ drive but there is no disk present. How would I do this, this is the code so far:
JFileChooser chooser = new JFileChooser();
chooser.setApproveButtonMnemonic('a');
chooser.setApproveButtonText("Save");
// create a file chooser with save dialog
int returnVal = chooser.showSaveDialog(c);
// If the user selects ok
if (returnVal == JFileChooser.APPROVE_OPTION) {
// Get the file the user selected
File file = chooser.getSelectedFile();
/ Get the name of the selected file
String name = file.getName();
     // Set the format name to null
String formatName = null;
// Get the index number of when the . occurs in the file name
int dot = name.indexOf(".");
     try {
     if(dot == -1) {
     file = new File(file.getParentFile(),
name + "." + defaultExtension);
     formatName = defaultExtension;
     else {
// else get the format name using a substring.
     formatName = name.substring(dot+1);
     // If the image cannot be saved, display an error message.
     if(!ImageIO.write(bi, formatName, file)) {
     file.delete();
     JOptionPane.showMessageDialog(c,
     "The image could not be saved. Please ensure that the extension is .jpg or .png",
     "Image save failed",
     JOptionPane.ERROR_MESSAGE);
     else {          // The image can be saved, so display a confirmation message
     JOptionPane.showMessageDialog(c,
     "The image has been saved to:\n"+
     file.getPath(),
     "Image Saved",
     JOptionPane.INFORMATION_MESSAGE);
     catch(IOException e) {               // Display an error message if save fails.
     JOptionPane.showMessageDialog(c,
     "The image could not be saved, no space on disk!!\n" + e,
     "Image save failure",
     JOptionPane.ERROR_MESSAGE);

Again I have tried this, but in my program if I try to save to the a drive when no disk is inserted, the JOptionPane i want to display is not coming up.
the system prints out
java.io.FileNotFoundException: A:\image.jpg <The device is not ready>
If that makes any sense to you

Similar Messages

  • When I update my nano ipod I get an error message "User ipod cannot be updated.  The disk couldnot be read from or written to."   How can I overcome this error message.

    In the iTunes window, when I update my nano ipod, I get an error message "User ipod cannot be updated.  The disk could not be read from or written to."   How can I overcome this error message.

    Hello there dilip77707,
    It sounds like you are getting this error message that your iPod cannot be read from or written to when you are trying to update your iPod Nano. I recommend the troubleshooting from the following article to help you get that resolved. Its pretty straight forward, just start at the top and work your way down as needed:
     'Disk cannot be read from or written to' when syncing iPod or 'Firmware update failure' error when updating or restoring iPod
    Thank you for using Apple Support Communities.
    All the very best,
    Sterling

  • I have recently bought a macbook and am using outlook 2011 as email. i am getting an error message 4.7.0 not allowed when sending emails how do I fix?

    i have a macbook and am using outlook 2011 as email.   receiving okay.   sending okay sometimes.  am now getting error message 4.7.0 not allowed when sending.  what is the cause? how do I fix please?

    I have discovered that the emails have in fact been sent but much later, maybe it's a network problem with the people i am sending it to.  so i checked my sent items and they are there, but at the time the email doesn't go straight into the sent box or drafts so i'm assuming it's disappeared and type it again.  i'll keep going with it, until someone can give me a possible solution or explanation as to what is happening.

  • I get error message: not enough space to download when I try to buy a tv series on Itunes. It tells me to delete photos or videos to make space, but I have no photos and videos. Help?

    I get error message: not enough space to download when I try to buy a tv series on Itunes. It tells me to delete photos or videos to make space, but I have no photos and videos. Help?

    I would guess that a TV series takes up a fair amount of storage capacity. It is just a standard message I think that may indicate that you are actually running low on storage space.
    If you go to Settings>General>About how many GBs are specified as being available?  If you are low on space maybe deleting some apps may help.

  • ITunes has stopped working error message on my Dell Latitude E6520 when trying to sync photos to my iPhone 3GS.  Why?!

    For some reason, I keep getting the "iTunes has stopped working" error message on my Dell Latitude E6520 when trying to sync photos to my iPhone 3GS.  I am using Windows 7 on my 64-bit computer.  iTunes will begin to optimize the photos in the folder I have directed it to (I am trying to load almost 3000 photos and videos), and it will go through optimizing all of them singularly, then get to the step where it says "optimizing" again, but does so in bigger groups.  It will get to about 2000, and then the error message "iTunes has stopped working" will pop up, and say that "Windows must close the program and will search for a solution, and if it finds one, it will notify me".  Why can't I sync these photos, and what can I do?  Thanks so much for the help, I really appreciate it!

    Same problem here! Moreover, for some reason, the pictures in my iPhone 3GS somehow have been divided into 2 folders, Photos and Medialibrary. And when I open iPhone as a folder through the explorer I can see only the Photos folder, but cannot see the Medialibrary folder which stores the photos taken before updating/upgrading the iPhone and getting separated folders!!! What the hack with all of this?!!! When I connect iPhone to PC it automatically opens iTunes and starts syncronizing it, but at the process of OPTIMIZING the photos (and according to the number of photos it shows, I see that it tries to syncronize that invisible Medialibrary folder) the process suddenly stops and error message pops out Tried the sync test, tried the button DEBUG in that pop out message, but NOTHING HELPS!!! Also, when I open the Medialibrary in my iPhone, the screen get sblack all through scrolling it down, only the video clips are shown there... >.<
    So, could you, apple developers, please, explain WHAT THIS PROBLEM IS ABOUT?!!!!!! FIX IT! I am getting ****** of to spend hours at the computer and reading those lame advises which do not help at all! I have my own things to do except reading your support websites. And I payed for the product ready to use, but not a halfproduct which problems should further be solved somehow by users..

  • TS3638 i have an internet connection but when i open app store it shows error message "cannot connect to app store".when i try to sign in with my valid apple ID and password it says "connection failed".i tried keychain access settings but it did not help.

    i have an internet connection but when i open app store it shows error message "cannot connect to app store".when i try to sign in with my valid apple ID and password it says "connection failed".i tried keychain access settings but it did not help.please help me!!

    Open Sysem Preferences from your Apple () menu top left in your screen then select the Firewall tab.
    Make sure the Firewall is turned off.

  • Getting error message "Could not create work area" when I open Bridge CC.

    I am getting an error message "Could not create work area" when I open Bridge CC.
    I have reset my workspace. I have closed and opened Bridge CC. I have deleted the !!-$$$AdobeOutputModule.workspace file in /Library/Application Support/Adobe/Bridge CC/Workspaces folder.
    I am not an expert computer user, so please explain in detailed steps like I am 5 years old. Thanks in advance for any help.

    I am experiencing the same problem!
    My mac is OS X Yosemite (10.10.1), Photoshop CC 2014.2.1, Bridge CC 6.1.0.115 and Camera Raw 8.7.0.309

  • I am getting the error message "cannot communicate with the server" when i try to sign into my apple account on my ipad - any ideas???

    i am getting the error message "cannot communicate with the server" when i try to sign into my apple account on my ipad - any ideas???

    Welcome to the Apple Community.
    The following article(s) may help you.
    Photo Stream ToU's

  • When I tried to update Itunes I got an error message telling me to reinstall.  When I try to reinstall I get a message "Apple Mobile Devide failed to start.  Verify you have sufficient privliges to start syem services"  Can anyone help here?

    When I tried to update Itunes I got an error message telling me to reinstall.  When I try to reinstall I get a message "Apple Mobile Devide failed to start.  Verify you have sufficient privliges to start syem services"  I'm not sure what this means, can anyone help here?  Thanks,

    I tried the temp fix you mentioned, it didn't work.  I could not delete all of the old itunes files, the uninstallers would crash half way through and if I tried to manually delete anything it also gave me an error, so reinstalling the older version would not work. 
    Frankly, this whole thing has got me ****** off.  judging by the amount of complaints here, there must be a lot of people having this problem, yet Apple has let it go on for almost 2 weeks.  What kind of inept coders are they employing if they can let an update that completely frags their software get through QA.
    Does anyone know of any programs that will play itunes music files?  I am just about done dealing with iTunes, but I've got a ton of music that I don't want to have to purchase all over again.

  • Get error message that skype has problem loading when computer is turned on the first time every day. this started when the latest firefox v6.0 was downloaded.

    get error message that skype has problem loading when computer is turned on the first time every day. this started when the latest firefox v6.0 was downloaded.

    ''mbratlie [[#question-1055011|said]]''
    <blockquote>
    It was working fine and I had no problems, and then one day I tried opening a window and it froze. When I tried quiting the program my whole window went black. The x to the close the window doesn't work. The only option I have in my tool bar is Firefox and nothing happens when I try to quit firefox. Every time I try to shut down my computer Firefox prevents it. I haven't updated Firefox yet, so it's an older program, but only by a month or two. What's going on and how do I fix it?
    </blockquote>
    This is the first time it's ever happened. I downloaded the new operating system for Firefox but I can't install it until the Firefox currently running on my laptop quits, which it won't.

  • When i connect my ipod shuffle to itunes i get an error message the ipod cannot be synced, the required disk cannot be found  anyone have this happen?

    When i connect my ipod shuffle to itunes i get an error message the ipod cannot be synced, the required disk cannot be found  anyone have this happen? How do i get past it?

    I seem to recall that this may be cause by overloading the USB bus (lack of power to go around).  Shut down your computer.  Reset the iPod shuffle using this procedure.
    http://support.apple.com/kb/HT1655
    Disconnect ALL peripheral USB devices, including keyboard and mouse.  Power up the computer.  If you need your mouse, connect it and launch iTunes.  Connect the iPod shuffle to a direct USB port and try the sync again.  See if there is any difference.

  • I get an error message "Adobe Reader has stopped working" when i try to use Firefox

    I get an error message "Adobe Reader has stopped working" when i try to use Firefox

    I have also retarted twice...

  • Error message: Helvetica Medium outline font missing when creating PDF's

    Error message: Helvetica Medium outline font missing when creating PDF's. Where can I downlaod it and why is it suddenly happening?

    OS? Version of ID?
    This means that either you have an extra Helvetica Medium font installed and it's interfering with ID finding the T1 version, or the T1 version is damaged. I found this really old thread that explains it fairly well: http://www.asadesigner.com/22-indesign/2d812de56777cc90.htm
    The good news is that it's probably only affecting the page information marks.

  • I get a recurring error message "Cannot Sign in to Itunes" when trying to activate my New York Times for iPad APP account.

    I get a recurring error message "Cannot Sign in to Itunes" when trying to activate my New York Times for iPad APP account. What is the solution?

    Same problem here.  Apparently NYT has zero support capability.  I emailed the. Three times and ive not even gotten an auto responder.
    I deleted the app, re-downloaded it and reset it.
    I have litrally no idea what to do
    Anyone?

  • How can I overcome error message "missing or invalid personalisation info" when trying to re-install Elements 3. I need to re-install Elements 3,

    How can I overcome error message "missing or invalid personalisation info" when trying to re-install Elements 3. I need to re-install Elements 3,
    @ Alternatively purchase an Elements 9 or 10.  Holding Elements13 but that needs OS 10.8 (Lion) and much of my data is in Appleworks, which is incompatble
    Apologies if I am using this incorrectly.  My first time here

    Hi.  Thanks for coming back to me.  I am using Mountain Leopard (OSX 10.6.8).  Had major problem and have re-formatted my H/D and re-installing software.  Must have lost a file in the process.  Would upgrade to Lion only I have a lot of vital data in Officeworks, but that is incompatible with Lion.

Maybe you are looking for

  • [AS] [CS2] Placing images in frames

    Hello, Thank you all for such a brilliant forum. In the past two weeks I've gone from knowing nothing about scripting to compiling two scripts which do exactly as I need thanks mostly to contributors to this forum. My question is about WHY my script

  • IPhoto 09 MobileMe Gallery Sync

    Friends, I apologize if this has already been asked. I have searched and searched and searched and just cannot find an answer. Here's what I am trying to figure out. I have a decent sized photo library being managed by iPhoto 09. I have diligently or

  • Version control: table modified date is changing but nothing seems to be modifying it! Why?

    I have a series of databases. They're mirrors of each other in structure, only the data inside them changes. There's a database for each customer. Each night I run a procedure that checks if anything has changed in the database since the previous run

  • Is there a How To on column sum totals, break formatting, 4 tabular reports

    Hi, I haven't needed to do a grand totals for a column until now. I see that there is built in BREAK FORMATTING. I looked for a how to on it but found none. Anyone have a good reference to explain basics? customizations? Thanks, Bill

  • PhotoShop Elements 4 "unexpectedly quit"

    My daughter has an eMac (1.42 GHz/512/160/SD/OS 10.4) with PSE 4. It frequently quits and gives the "unexpectedly quit" message. There does not appear to be any consistent pattern as to when this will occur. Anyone have a solution for this? iMac w/In