• Post Reply Bookmark Topic Watch Topic
  • New Topic

copying files from src to dstn directory  RSS feed

 
mythily prakash
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
Any one tell me how to copy a file named "C:/myfile/fil1.java" to "c:/My java/" with the same name fil1.java
 
amod gole
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi mythily prakash,

first you hava to create two file object using File class (for source and destination)

pass first object from where you are reading data to FileInputStream class and and second second object to FileOutputStream for writing to file (destination)

use read and Write mehod in while loop with cond_n of end of file (-1)
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Much of this is inherently dependent on the platform. For example, it may or may not work if the destination file already exists. If you want a more robust solution what Amod suggested may be more appropriate. I'm honestly not sure of the pitfalls of either or the best workaround, but renameTo() is an easy approach if you're not too worried about it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!