How do i move a file from one directory to another?

Can anyone help me in moving a file from one directory to another?
The following code just does not work!!
File source_file = new File(source_file);
if(source_file.exists())
File dest_file = new File(destination_file);
if(!dest_file.exists())
boolean moved = source_file.renameTo(dest_file);
System.out.println("moved.."+moved);
The varirable moved is always false.
Can anyone tell me whts wrong in this code?

The problem in your code is you used file object as argument when you create a new File. I changed a little bit codes and it should be fine now.
String source_file1="test111.txt";
String destination_file1="test222.txt";
try{
     File source_file = new File(source_file1);
     if(source_file.exists())
          File dest_file = new File(destination_file1);
          if(!dest_file.exists())
               boolean moved = source_file.renameTo(dest_file);
               System.out.println("moved.."+moved);
catch(Exception e){
           e.printStackTrace();
}

Similar Messages

  • To Move Multiple Files from one directory to another.

    Hi,
    I need to move multiple files from one directory in UNIX (application server ) to another. I need something like an FM 'STRALAN_COPY_FILES' which is also valid in ECC 6.0.
    Thanks in advance.

    Hello Sachin
    Below you see a copy of how to use EPS_FTP_PUT using transaction SE37.
    Import parameters               Value             
    RFC_DESTINATION =                 NONE              
    LOCAL_FILE             =         filename          
    LOCAL_DIRECTORY   =              /dir1/dir2        
    REMOTE_FILE             =        filename          
    REMOTE_DIRECTORY   =             /dir1             
    OVERWRITE_MODE        =          F        " force -> overwrite existing file                 
    TEXT_MODE                    =   B               " binary
    TRANSMISSION_MONITOR            X       " display transmission monitor            
    *RECORDS_PER_TRANSFER            10                
    *REQUESTED_FILE_SIZE             0                 
    *MONITOR_TITLE                                     
    *MONITOR_TEXT1                                     
    *MONITOR_TEXT2                                     
    *PROGRESS_TEXT                                     
    *OBJECT_NAME  
    Regards,
      Uwe

  • Move stickie file from one mac to another, move stickie file from one mac to another, How do I move stickie file from one mac to another

    How do you transfer the stickie data file from one mac to another?

    I think this is the file -
    In (hard drive) > Users > yourhomefolder (the one with the house icon) > Library, look for a loose file named StickiesDatabase
    Copying that file to the same location on the new machine (and replacing the file there now) should move the notes. It is probably a good idea that both machines be running the same OS X version.

  • How to Move  a file from one Directory to another directory.

    Hi All
    i am having a Java standlone Application reqiurements are
    1---->Connection pool To be Created.
    2---->Using Thread to read Multiple Files Simulatneously.
    3----->After Reading Those file I have to Move it to another folder.
    Plz help me.If possible give me sample code .
    I am in deep trouble for this project.

    Use java.io.File.renameTo(...) (look it up in the API documentation).
    Renaming a file doesn't work if you're trying to move files from one disk to another disk. In that case, you have to copy the file and delete the original.

  • How do I move a file from one catalog to another

    I created a new catalog by mistake, I imported a file to this catalog, how do I move the file to the catalog that I have been using?

    You CAN export the catalog and then import and merge it to your correct catalog.
    But if it's just one file, why not just delete the new catalog and reimport the one file???
    tom

  • How do I move all files from one project, to another hard drive?

    I am using CS3- I created a project on one hard drive, began editing, etc.- but now I'd like to move that project to another hard drive.
    Where are all of the files associated with it so I can move it successfully?
    Thanks!

    You will also find links to many
    free tutorials in the PremiereProPedia that will quickly show you how things are done in Premiere Pro.
    Cheers
    Eddie
    PremiereProPedia   (
    RSS feed)
    - Over 300 frequently answered questions
    - Over 250 free tutorials
    - Maintained by editors like
    you
    Forum FAQ

  • How do I move a file from one folder to another in th K1?

    When I long click a file name a I get a popup list and move is listed. When I press move, the filename gets highlighted, but I can't drag and drop it. What am I doing wrong?
    Solved!
    Go to Solution.

    Which file explorer app are you using?
    If it's the "File Mgmt." app, with the round icon that looks like the front of a folder, after long-clicking the file and selecting Move, go to the folder that you want that file moved to, and select Operation at the top, then Paste.  It is not drag-n-drop.

  • How do I move a file from one catalog to aanother?

    How do I move a file from one catalog to another?

    The ambiguity in your first question was that you didn't state which product you were on about - Photoshop?, Lightroom? Bridge? Elements? and which version of these? As I said you clarified this in your second question. I did say that I felt that you have a hidden agenda because you escalated in to insults about Adobe within 5 minutes or so of your first question. It appeared to me that what you were wanting to do right from the outset was to vent your anger at Adobe. That wasn't stated directly in any of your posts hence my opinion that you had a hidden agenda.
    As Silk rooster said we are not employees of Adobe just users of their products (look for the word staff next to a users name to identify if they are a forum member or a member of staff).
    Incidentally before you correct my spelling (ambig(e)uous) make sure that your own post is free from spelling and or grammatical errors. I am dyslexic and therefore rely on spellcheckers, which aren't always perfect, but hey - thanks for pointing out my shortcomings.
    Cheers
    John

  • How do I move a contact from one group to another?

    On my device, or in iCloud on the web, how do I move a contact from one group to another.  This should be as easy as it is with calender items, but the only solution I've found is to change your default contact group, and email the contact to yourself.  Then tap the contact, and add it to your contact list.  You can then delete the original.  Is there an easier way???

    Hi rjwrjw11,
    Thanks for visiting Apple Support Communities.
    If you want a song to be listed under a different album in iTunes, you can edit the song information:
    Fixing Incorrect Song or Album Listings in iTunes
    http://support.apple.com/kb/TA24677
    Editing Track Information in iTunes
    To view and edit a song or video's info in iTunes:
    Click once on the track title to select it
    From the File menu, choose Get Info
    Click the Info tab
    Best,
    Jeremy

  • Move a file from one lacation to another in FTP

    Hi Experts,
    i have scenario were i have to move a file from one location to another in a FTP the source and the Target  structure are same can we go  with only configuration(ID) why because there is no mapping done but i have dbout when we create a sender agreement,receiver agreemant we need to mention the Message Interface is there any way to skip the IR(Design) part
    Do provide inputs
    Thanks,
    Sampath

    hi ,
      you can skip your IR part. follow this blog
    /people/william.li/blog/2006/09/08/how-to-send-any-data-even-binary-through-xi-without-using-the-integration-repository
    /people/shabarish.vijayakumar/blog/2006/04/03/xi-in-the-role-of-a-ftp
    Edited by: Robin on Jan 20, 2009 11:50 AM

  • How do I move a song from one album to another?

    how do I move a song from one album to another?

    Hi rjwrjw11,
    Thanks for visiting Apple Support Communities.
    If you want a song to be listed under a different album in iTunes, you can edit the song information:
    Fixing Incorrect Song or Album Listings in iTunes
    http://support.apple.com/kb/TA24677
    Editing Track Information in iTunes
    To view and edit a song or video's info in iTunes:
    Click once on the track title to select it
    From the File menu, choose Get Info
    Click the Info tab
    Best,
    Jeremy

  • How do I move an object from one photo to another and then change the scene, i.e.  winter to sum?

    How do I move an object from one photo to another and then change the scene, i.e.  winter to summer?

    OK.
    Open the picture with the new scene. This will be your canvas.
    Open the picture with object A, select it with one of the selection tools, go to Edit>copy
    Go back to the new scene/canvas, Go to Edit>paste
    Repeat for object B
    Use the move tool to position A & B, each on its own layer. Use the corner handles of the bounding box to resize, if necessary
    You should have 3 layers: Background layer, and the 2 layers with A & B
    Note: It's best if the resolution of the 3 picture files is the same value.

  • How can I move a photo from one project to another

    How can I move a photo from one project to another without creating a duplicate so I have the same photo in two projects.
    I seems to me in the past when I moved the photo from project 1 to project 2, I would get a number showing the # of photos being moved and you could drag and drop in the 2nd folder and the photos would disappear from project 1 and show up in project 2. is there a setting I am missing.  Now when I drag and drop the photo no red # shows up and the photo stays in project 1 and also shows up in project 2 apparently creating a duplicate.
    Any suggestion?

    Now when I drag and drop the photo no red # shows up and the photo stays in project 1 and also shows up in project 2 apparently creating a duplicate.
    The projects are the basic containers.  Each image and all its versions are in exactly one project.
    You can use an image in many albums, without duplicating it, also in many products like books, screensaver, slideshows.  But the projects are the basic structure of the library and you cannot have the same image in two different project, without duplicating it by storing the same original image files twice. Use albums to organize your library thematically.
    Sorry, I misread your question.   Dragging an image file between projects should move the image and all its versions to the other project.  Aperture should only duplicate the image, if you hold down the alt/options key while dragging and move the image otherwise.
    Which Aperture version are you using? And which MacOS X version?  Is your profile signature "MacBook Pro with Retina display, Mac OS 9.2.x, Aperture 3.5.1" still valid?
    In Aperture 3.6 on MacOS X 10.10.1 dragging between projects is still working as expected:

  • Ssis - move files from one directory to another and rename destination file if present

    Hello,
    How is it possible to move files from one directory to another directory and if the file already exists in destination directory then rename it?
    Thanks

    1. Use a foreach loop with file enumerator pointing to first directory.
    Inside loop have a ssis variable of type string to get filename (@[User::FileName])
    Choose option as Fully Qualified in loop
    2. Add another variable called @[User::DestFileName], set EvaluateAsExpression true for it and set expression like this
    REPLACE(@[User::FileName],<source directory path>,<destination directory path>)
    put actual paths in above expression in your case
    and another variable called @[User::RenameFileName], set EvaluateAsExpression true for it and set expression like this
    REPLACE(@[User::FileName],".","_old.")
    3. Create a boolean variable say @[User::FileEXists]
    4. Add a Script Task inside the loop and pass @DestFileName variable in ReadOnly mode and FileExists in ReadWrite mode
    Inside Script Task write code as per below
    http://blog.dbandbi.com/2013/11/13/check-file-exists-ssis/
    5. Add File System Task choose operation as Rename File, Select IsSourcePathVariable as true and select @[user::DestFileName] variable and IsDestinationPath variable as true and select @[user::RenameFileName] variable
    6. Choose ExpressionAndConstraint option for precedeence constraint from ScriptTask to above File System Task and choose constraint as OnSuccess and expression as
    @FileExists == True
    7. Add another File System task with operation as Move File Select IsSourcePathVariable as true and select @[user::FileName] variable and IsDestinationPath variable as true and select @[user::DestFileName] variable. Join Script Task as well as
    File System Task above to this task and choose constraint as OnSuccess and Multiple Constraint option as Or (dotted line)
    Then once executed it will work as per your requirement
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How do I move Contacts & Calendar from one User to another User on the same Macbook Pro?

    How do I move Contacts & Calendar from one User to another User on the same Macbook Pro? OSX 10.9.5

    is this second library in a different account on the computer?
    Look at Home Sharing.
    iTunes: How to share music and video - http://support.apple.com/kb/HT2688 - about Music Sharing and Home Sharing
    Home Sharing Support page - http://www.apple.com/support/homesharing/
    iTunes: Setting up Home Sharing on your computer - http://support.apple.com/kb/HT4620
    iTunes Home Sharing now works between users on same computer - https://discussions.apple.com/thread/3865597

Maybe you are looking for

  • Aperture, iPhoto, Mail, FCP X, Motion and Compressor suddenly kaput!

    Yesterday I discovered that Aperture and iPhoto, which I hadn't used for several weeks, were refusing to open and throwing up an error message saying there was a "problem and they probably weren't compatible with this version of the  operating system

  • MPEG on the N95

    Can any1 tell how i can download and view mpeg video clips with the n95, only mp4 and 3gp downloadable at the mo. I don't see the point of having such a good fone and then having to wait till u get to a pc to download, convert and then send to your f

  • HELP! ZEN Sleek Reinstall Softw

    I did a fresh install of XP on my laptop and I'm installing my programs etc but I?can't find?my installation cd for my ZEN Sleek !!! What do I need to download to get it connected to my laptop so I can update its music?Cheers,Jaqian

  • Isn't this a valid way to write queries ?

    Guys, Please can you let me know if this is valid way of writing the query. I seem to get an error saying missing right parenthesis when i try to execute it. But the queries work individually.. I want to use it something like an inline view Cheers G

  • NO one answered me! Need help: Iphone 5 doesn't search for  a signal!

    Everytime I am in library, my cellphone doesn't have a signal. So my phone only gets wifi. When I leave the library, my iPhone 5 doesn't search for a signal. It shows me "no service" until I turn on/off the airplane mode. Then the phone starts to sea