File.renameTo() bugg? Leaves the file open

I came across the strangest behaviour of File.renameTo() for the following steps:
1. Rename a file - successful
2. Rename the same file again - will fail. Also delete will fail.
-------- some code ----------
File file=new File("F1");//nonexistent file
//write some to the file - just to make the file to be created
RandomAccessFile rFile=new RandomAccessFile(file,"rw");
rFile.writeBytes("Hello");
rFile.close();
//A successful rename
boolean renamed=file.renameTo(new File("F2"));
System.out.println("renamed="+renamed);
//This is commented code for now
//rFile=new RandomAccessFile(file,"rw");
//rFile.close();
//This rename fails!
renamed=file.renameTo(new File("F3"));
System.out.println("renamed again="+renamed);
As it seems File.renameTo() sets the file to open, since neither renameTo or delete will work after a renameTo.
BUT, if I uncomment the commented code, it will work again! I just open a dummy RandomAccessFile (FileInputStream would work as well I guess) and then close it, and somehow the file is set to closed again, and the second renameTo() will work.
Is this a bugg in File.renameTo()? I run on windows XP and have java 1.4.1_02-b06. I couldn't find any comment about this in the Bug Database.
Gil

Aha! so the reason why the opening of the dummy RandomAccessFile did it in my previous code, was becase it created the old File "F1" again that could be renamed again. So the correct code should instead be:
-------- some code ----------
File file=new File("F1");//nonexistent file
//write some to the file - just to make the file to be created
RandomAccessFile rFile=new RandomAccessFile(file,"rw");
rFile.writeBytes("Hello");
rFile.close();
//A successful rename
File file2=new File("F2");
boolean renamed=file.renameTo(file2);
System.out.println("renamed="+renamed);
//Now this rename also succeeds!
renamed=file2.renameTo(new File("F3"));//do rename on file2!
System.out.println("renamed again="+renamed);
Gil

Similar Messages

  • Can I leave the display open for say all day while downloading torrent file

    Sometimes it takes all day to download a torrent file can i leave the display on or should i turn it off and will my macbook keep downloading the file thank you

    It's fine to leave it on but you can also just set the display to go to sleep and let your computer keep working. The settings are under *System Preferences* in *Energy Saver*. I usually have mine turn off after 15 minutes so it will rest while my download or other work continues.

  • Should I leave the email open on my MBP

    Hello all, should I leave my mail open or closed on my MBP?  I like to know when I have mail and thought that I might just leave it up?  Also I do like to hear a mail sound when mail comes in.

    That is up to you. No harm will come to your Mac or the mail program by leaving it open.

  • Leave the lid open when plugging a MBP into a 30inch?

    I play games, watch video & really try and get the most out of my Macbook Pro. When I connect it to my 30inch ACD I usually leave the lid closed... but recently have been opening it once I plug it in, to try and help with heat.
    Is this necessary?

    Close it. If you leave it open the internal display will be lit and will display something, so you have to set it to Mirroring or Extended Display, but if you close it then the 30" gets the entire video card.
    To prevent overheating, put the laptop on a hard surface so that air can flow under it, and do not block the large long vent that spans the entire back of the laptop. Whether it's open or closed isn't going to make as much difference as the airflow through the vent and past the bottom.

  • Is there a way to switch off by default the video on FaceTime? I only ever use this app for audio/calls and hate the video being on. I especially hate that if I leave the app open to receive calls it means the camera and green light are on.

    My issue is that I can't find a way to have the camera switched off when the app is open and so this means if I want the app open all day to receive calls then the camera is going to be on the whole time. Even if it didn't potentially drain the battery, or add to the CPU usage or whatever else may cause any problems whatsoever (wheel of death!), I just don't want the camera on as I don't see myself ever wanting to use the video call feature but I would use the audio/call multiple times throughout the day to make and receive calls. The camera being on when the app is open is enough to prevent me from using the app. Also ever since seeing that episode of criminal minds where if you saw the green light on above the screen then it meant the killer was watching you!
    Basically I just can't believe there isn't a way to disable the camera whilst having the app running. I know when initiating an audio call the camera goes away, but I would like the camera away the whole time. To me it just would make sense that if you click the video option then the camera is on, and if you click the audio option then the camera goes off. It just seems waaaaay to basic a thought for apple to have missed... Let's face it, we're not all as pretty as the people in the apple adverts and don't want to see our ugly mugs staring back as us when we work all day at our macs!

    I have exactly the same concern. It seems it would be a simple fix for Apple to allow users to turn off the camera (and even the mic) while keeping FaceTime open -- especially now that it turns out FaceTime must remain open in order to send and receive iPhone calls on a Mac.
    I like to think this new functionality of FaceTime will be baked into a future release of Yosemite, as the current setup has that not-quite-finished feel of a work in progress. In the meantime, there's nothing like a little piece of Post-It stuck over the camera to keep the NSA from watching your face as you type a post to the Apple Support Communities.

  • Why is the mobile site for iPad requiring a login every time I go to gmail (even if I leave the tab open while I use another tab?

    For the last week or so every time I go to gmail (even when I've left the tab open) I am required to sign in. This is an unnecessary step that I really don't want to do. I don't like the gmail app. And I feel like this sign in issue is forcing me to use the app. Why is this happening? Is there a way around this?
    Thank you for any input.

    Can you post back here a screenshot from this issue?

  • IMAQ USB Close leaves the camera open

    Hi,
    I hope somebody can help me with that one. I have a DirectShow compliant USB camera, that I got to work with the IMAQ USB VIs. I can acquire images, enumerate the devices and get the options dialog. However calling the IMAQ USB Close VI does seem to have any effect. As the next time I try to call IMAQ USB Open afterwards I got error -1074396024 until I terminate the host process and restart LabVIEW again.
    I am using LabVIEW 8.0, on W2k German
    I also tried the samples (e.g. Grab.vi) provided with the same effect.
    Running a tool that collects system debug messages (send via OutputDebugString) I got 'Export: Break Connect' coming from the IMAQ USB Close VI, but I also see, that the underlying DirectShow Interface doesn't receive any close call. Is there an Interface missing in the DirectShow interface (which?) or is this a bug in the IMAQ USB Interface (not very likely as a lot of guys seem to be happy with it)?
    Can anybody help please?
    Greetings,
    Stefan

    Stefan,
    below is an excerpt about the system requirements for IMAQ USB:
    - Windows 2000/XP (English, Italian,
    Japanese, French, Italian, Norwegian, Dutch, Spanish/Portuguese,
    Russian, and simple Chinese)
    - LabVIEW 7.0 or higher with NI Vision 7.1 or higher for the USB LabVIEW support.
    - Vision Assistant 7.1 or higher for the USB Vision Assistant plugin module.
    In general IMAQ USB is not supported but I will forward the information to R&D.
    The following link povides other possibilities:
    http://digital.ni.com/public.nsf/allkb/274a74a901399d0486256f32007295f9
    Regards,
    ThSa
    http://www.newgistics.com

  • My macbook air 11" wont sleep if I leave the lid open

    even though I have checked the power saver settings and it should sleep after 15 minutes.  Instead the battery completely drains!!!

    Hi felicityc,
    If you are having sleep issues with your MacBook Air, you may find the following article helpful:
    Mac OS X: Why your Mac might not sleep or stay in sleep mode
    http://support.apple.com/kb/HT1776
    Cheers,
    - Brenden

  • Fix a Lion file-opening hang in Mac OS X 10.7.2  (Ubiquity folder)

    http://www.macworld.com/article/163227/2011/10/fix_a_lion_file_opening_hang_in_m ac_os_x_10_7_2.html#lsrc.rss_main

    Quit Calendar if it's running. Triple-click the line below to select it:
    ~/Library/Calendars
    Right-click or control-click the highlighted line and select Services ▹ Reveal. A Finder window should open with a folder selected. Move the selected folder to the Desktop, leaving the window open.
    Try again to sign out of iCloud. If you're successful, put the folder you moved back where it was. Launch Calendar and unsubscribe from any calendars that are not based in iCloud. You can add them back later, but make sure you don't synchronize them to iCloud.

  • My emails in mail have just disappeared leaving the headers of date etc

    my emails in mail have just disappeared leaving the headers of date etc
    any one out there who has had this before
    smburc

    Quit Mail. Force quit if necessary.
    Back up all data. That means you know you can restore the Mail database, no matter what happens.
    Triple-click anywhere in the line below on this page to select it:
    ~/Library/Mail/V2/MailData
    Copy the selected text to the Clipboard by pressing the key combination command-C. In the Finder, select
    Go ▹ Go to Folder
    from the menu bar. Paste into the box that opens (command-V), then press return.
    A folder window will open. Inside it there should be files with names as follows:
    Envelope Index
    ExternalUpdates.storedata
    Move those files to the Desktop, leaving the window open. Other files in the folder may have longer names that begin as above. Move those files, if any, to the Trash.
    Log out and log back in. Relaunch Mail. It should prompt you to re-import your messages. You may get a warning that the index is damaged and that Mail has to quit. Click OK. Warning: The process may take hours if you have gigantic mailboxes. For reasonable-sized mailboxes, it should only take a few minutes.
    Test. If Mail now works as expected, you can delete the files you moved to the Desktop. Otherwise, post your results.

  • Is there a way to use an external display while keeping the Macbook open?

    I'm trying to use my external display as my primary (and only display). I would be operating in clamshell mode, but this can lead to overheating issues. Is there an easy way to leave the Macbook open but turn its screen off manually when another display is connected?
    I've found that by closing the macbook, plugging in a mouse, waiting for the macbook to start in clamshell mode, and then opening the display, I can do this. Is there an easier way (i.e., an option to tell the macbook display to turn off)

    could you not just connect it with the vga adapter and then turn the brightness of your screen all the way down so there is no light? i had to do that for my ibook g4 when i cracked the lcd, but thankfully i have my macbook now.

  • Sleeping with the lid open

    This is so basic, I am embarrassed to post, but here goes. I have a MacBook that sleeps just fine with the lid closed. Light pulses, spin up noise when I open the lid. Recently I have noticed that when I leave the lid open, the screen goes black in the appointed time (from setting in System Preferences), but the little light on the front does not pulse nor do I get the spin-up sound when I move the mouse, etc.
    Now for the embarrassing part -- has it always worked this way, or is this something new? I feel sure that previously I could leave the lid open and after the appropriate time, the light would pulse, etc. But not now.
    I have reset the PMU several times, checked the sleep preferences, made sure that there was nothing running, no bluetooth activity, etc. But no joy. I called Apple, and the tech there (who quite frankly was hard to understand, but I think I did understand him enough) told me that the behavior I am experiencing is correct. What I want to know is whether the MB sleeps with its lid open and no pulsing light (just on steady). Is my machine sleeping or not?
    Thanks in advance!

    Thanks for your replies! I have checked my settings repeatedly -- currently (for testing purposes) set for the screen to sleep after 2 minutes, the hard drive to sleep after 2 minutes, hard drive to sleep when possible, etc. Bluetooth is not the problem, set to not wake for bluetooth activity, as is the "wake for ethernet". I have even restarted the computer, left it at the login page, and the behavior remains (no pulsing, no spin-up sound). Now that I think about it, when I close the lid for sleep, the light pulses, but no spin-up sound. Hmmm, should I be worried?
    Just seems to me that with my G4 PowerBook and this MB earlier, that with the lid open the light would pulse, and just a while ago started not pulsing. Seems about the time I did a software update, but can't be sure. This issue is somewhat important to me because I use WireTap Pro to schedule recording of a couple of radio shows, and need to leave the lid open so WTP can "wake" it to record.

  • Using bootcamp was installing windows xp, at the select ntfs or fat format selected "leave the current file system intact." How can that be changed to a correct choice. Mac side opens correctly. Windows shows disk error.

    using bootcamp, was installing windows xp, at the select ntfs or fat format mistakenly selected "leave the current file system intact." How can that be changed to a correct choice. Mac side opens correctly. Windows shows disk error. and doesn't respond to press any key. When looking in the startup disk section, windows on boot camp can be seen, but not selected. (13"MacBook Pro  10.6.8)

    Have a read here http://support.apple.com/kb/TS1722 for solution.
    Stefan

  • I opened a website that said that all of my files had been encrypted. A popup appeared and asked if I wanted to leave the page, but when I tried to, it wouldn't let me.  How do I know if this is a real problem or not?

    I was researching information for a class and I clicked on a website that said that all of my files had been encrypted.  A popup appeared and asked if I wanted to leave the page but when I tried to, it would let me.  I had to force quit Safari in order to do so.  How do I know if this is a real problem or not? 

    It's a JavaScript scam that only affects your web browser, and only temporarily.
    1. Some of those scam pages can be dismissed very easily. Press command-W to close the tab or window. A huge box will pop up. Press the return key and both the box and the page will close. If that doesn't happen, continue.
    2. From the Safari menu bar, select
              Safari ▹ Preferences... ▹ Security
    and uncheck the box marked Enable JavaScript. Leave the preferences dialog open.
    Close the malicious window or tab.
    Re-enable JavaScript and close the preferences dialog.
    3. If the Preferences menu item is grayed out, quit Safari. Force quit if necessary. Relaunch it by holding down the shift key and clicking its icon in the Dock. From the menu bar, select
              Safari ▹ Preferences... ▹ Privacy ▹ Remove All Website Data
    to get rid of any cookies or other data left by the server. Open your Downloads folder and delete anything you don't recognize.

  • I have an iMac. , mid 2007.  Frequently, when I take an action, the little color wheel starts spinning and goes on for quite awhile.  Save a file, close a file, open a file, open a window, it's all random.  Somtimes it stalls, sometimes it doesn't.  Why?

    I have an iMac. , mid 2007.  Frequently, when I take an action, the little color wheel starts spinning and goes on for quite awhile.  Save a file, close a file, open a file, open a window, it's all random.  Somtimes it stalls, sometimes it doesn't.  Sometimes long, sometims short.  Why is this happening?

    Consider adding more memory. Be sure you have adequate free space on the hard drive - 15 GBs or 10% of the drive's capacity, whichever is greater. Do not run too many applications concurrently. Visit The XLab FAQs and read the FAQ on resolving the SBBOD.
    Do some maintenance:
    Repair the Hard Drive and Permissions
    Boot from your Leopard Installer disc. After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Utilities menu. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the installer.
    If DU reports errors it cannot fix, then you will need Disk Warrior and/or Tech Tool Pro to repair the drive. If you don't have either of them or if neither of them can fix the drive, then you will need to reformat the drive and reinstall OS X.
    Kappy's Personal Suggestions for OS X Maintenance
    For disk repairs use Disk Utility.  For situations DU cannot handle the best third-party utilities are: Disk Warrior;  DW only fixes problems with the disk directory, but most disk problems are caused by directory corruption; Disk Warrior 4.x is now Intel Mac compatible. Drive Genius provides additional tools not found in Disk Warrior.  Versions 1.5.1 and later are Intel Mac compatible.
    OS X performs certain maintenance functions that are scheduled to occur on a daily, weekly, or monthly period. The maintenance scripts run in the early AM only if the computer is turned on 24/7 (no sleep.) If this isn't the case, then an excellent solution is to download and install a shareware utility such as Macaroni, JAW PseudoAnacron, or Anacron that will automate the maintenance activity regardless of whether the computer is turned off or asleep.  Dependence upon third-party utilities to run the periodic maintenance scripts was significantly reduced since Tiger.  These utilities have limited or no functionality with Snow Leopard or Lion and should not be installed.
    OS X automatically defragments files less than 20 MBs in size, so unless you have a disk full of very large files there's little need for defragmenting the hard drive. As for virus protection there are few if any such animals affecting OS X. You can protect the computer easily using the freeware Open Source virus protection software ClamXAV. Personally I would avoid most commercial anti-virus software because of their potential for causing problems. For more about malware see Macintosh Virus Guide.
    I would also recommend downloading a utility such as TinkerTool System, OnyX 2.4.3, or Cocktail 5.1.1 that you can use for periodic maintenance such as removing old log files and archives, clearing caches, etc.
    For emergency repairs install the freeware utility Applejack.  If you cannot start up in OS X, you may be able to start in single-user mode from which you can run Applejack to do a whole set of repair and maintenance routines from the command line.  Note that AppleJack 1.5 is required for Leopard. AppleJack 1.6 is compatible with Snow Leopard. There is no confirmation that this version also works with Lion.
    When you install any new system software or updates be sure to repair the hard drive and permissions beforehand. I also recommend booting into safe mode before doing system software updates.
    Get an external Firewire drive at least equal in size to the internal hard drive and make (and maintain) a bootable clone/backup. You can make a bootable clone using the Restore option of Disk Utility. You can also make and maintain clones with good backup software. My personal recommendations are (order is not significant):
    Carbon Copy Cloner
    Data Backup
    Deja Vu
    SuperDuper!
    SyncTwoFolders
    Synk Pro
    Synk Standard
    Tri-Backup
    Visit The XLab FAQs and read the FAQs on maintenance, optimization, virus protection, and backup and restore.
    Additional suggestions will be found in Mac Maintenance Quick Assist.
    Referenced software can be found at CNet Downloads or MacUpdate.
    Be sure you have an adequate amount of RAM installed for the number of applications you run concurrently. Be sure you leave a minimum of 10% of the hard drive's capacity as free space.

  • My picture files open up off center so I cannot see all of the bottom part of the picture.

    Hi,
    My picture files open up off center so I cannot see all of the bottom part of the picture. The ruler across the top read "0" to 13.5". Down the left side of the picture the ruler reads 3", 2",1", 0, 1", 2",3" etc. This leaves a three inch empty space at the top of my viewing area and I lose three inches of the bottom of my picture. I cannot figure out how to adjust this. I have tried the screen modes  and they do not fix my problem.  What can I do to solve this problem?

    Please provide sensible details about your platform, exact version of your OS, exact version of Photoshop, complete details baout your setup, hardware details, monitor resolution, etc.
    Please read this FAQ for advice on how to ask your questions correctly for quicker and better answers: 
    http://forums.adobe.com/thread/419981?tstart=0
    Thanks!

Maybe you are looking for

  • What specs. do I need to look at to not get chirping sounds at the end of a sound fi

    Hi all,?I am trying to run an experiment for a doctoral project and I need some help. I have a really expensi've sound card called the lynx one that I have no problems with. Recently my school purchased the soundblaster x-fi extreme audio sound card

  • Could not resolve fx:Declarations to a component implementation.

    Hi.. Am getting an error message Could not resolve  <fx:Declarations> to a component implementation. and Could not resolve  <fx:Script> to a component implementation. Am trying  the following mxml code. <s:Application xmlns:fx="http://ns.adobe.com/mx

  • Audigy 4 mic

    Hi, I would like to buy an Audigy 4 pro card but I need a very low noise mic input. Is A4 Pro really high quality in this field? Now I have Santa Cruz - Turtle Beach, just bought external mic preamp and noise level is absolutely terrible. I wonder if

  • Is this a bug? createdBy populated with value "1"

    I have a field in entity object mapped as historical column "createdBy". once I create a new record, this field populated as login user name. -- this works fine. However, after I specify this field "refresh after inserted/updated". this field populat

  • Request for iOS

    Hi there, I am new in this forum, and posting here as I haven't seen any other way to send requests for future releases. I am quite sad to see there is no forum dedicated to iOS, as my post is related to it. Firstable, want to say I have been quite h