• Post Reply Bookmark Topic Watch Topic
  • New Topic

to copy file from one directory to other

 
prachi jahagirdar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
i am trying to copy a file from one directory to other.
if i don't want to use Runtime.exec(), how do i do it?
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read in one file and write to another using java.io package.
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at these examples at JavaAlmanac.com:
  • e172. Copying One File to Another (uses classes from ther New IO package java.nio)
  • e25. Moving a File or Directory to Another Directory (uses java.io)

  • Keep in mind that the second example is moving a file, not copying, but you can adapt the code. Also keep in mind for the first example that a fileInputStream can be create with a File object used in the constructor rather than a String, and in turn File objects can be created using paths and filename.
    Lastly, search the I/O and Streams forum here at JavaRanch for "Copy File" and you'll find some other posts on the subject,
     
    Dirk Schreckmann
    Sheriff
    Posts: 7023
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Moving this to the I/O and Streams forum...
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!