• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to copy paste a file from one dir to another????  RSS feed

 
S Rubia
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , jgrus
im having a problem related to File class,when i want to move one file from one
directory to another directory and i found no such method in File class in jdk1.3 ,so
1------------what should i do for my this problem (means how to copy paste or cut paste
the files from one directory to another).
2------------Is there any support has been included in higher versions means in 1.4 or 1.5.
Thanks .
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think there is a build-in support for files with drag'n'drop/ cut'n'paste.

To copy it, you need only to get the filename, and the destination dir, so you may copy it yourself with FileReader/ Writer or Streams or both.

To move it, you would have to java.io.File.delete() it afterwards.
(had a quick look to my 1.5.0-beta2 - docs)
[ June 01, 2004: Message edited by: Stefan Wagner ]
 
S Rubia
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stefan ,for ur reply BUT
the problem is that there are usually too different types of files in a directory like pictures ,videos,pdf formate , text files , audio files so it is nearly an impossible and time taken task to use file streams for all these type of formats,(means 1st check which type of format is it either byte or character and then use a suitable stream , u know what i mean)
Could there be any more sensible thing possible to drag n drop files,please if any do tell me,
i cant beleive that java dont give support for such a necessary and common task
thanks
 
S Rubia
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And ya u forget to send the link of ur doc
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To copy a file, all you need are FileOutputStream and FileInputStream. (Or FileChannels). It doesn't matter what the contents are, since you're not trying to understand the contents - you're just copying.

Or use FileChannels:

This can be much faster, especially for large files. Though on some systems there may be no difference in performance.

Now to move a file, rather than copy it, you can use the renameTo() method in the File class.

And ya u forget to send the link of ur doc

Try

http://java.sun.com/docs/

or more specifically

http://java.sun.com/j2se/1.5.0/docs/

or

http://java.sun.com/j2se/1.5.0/docs/api/index.html
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!