Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Moving a file to another directory  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

im having problems with moving a file to another directory. Im using a JFileChooser for the user to pick a file, then i use the renameTo() method to move it to another directory. for some reason, the renameTo() method returns false. here is the code, please tell me whats wrong:



any help would be appreciated.
Thanks.
 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Ben,
I used to get the same problems some time back. I discovered two reasons for those unsuccessful file renames. I don't think it will be of any help to you but anyways, here they are:
  • When any Input/Output Streams were left open upon the target file
  • OR, when the file already existed in the target location


  • If I am wrong please correct me.
     
    Java Cowboy
    Sheriff
    Posts: 16084
    88
    Android IntelliJ IDE Java Scala Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Also you cannot move a file from one disk (or partition) to another using the renameTo method. The to and from directories have to be on the same disk (C:, for example).
     
    Ben Wong
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    yup that was the problem. The files were in separate directories.
    The solution i used in the end was to create an InputStream and OutputStream then send the bytes over using the write() method.

    thanks for your help.
    [ April 20, 2006: Message edited by: Ben Wong ]
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!