• Post Reply Bookmark Topic Watch Topic
  • New Topic

copy files  RSS feed

 
Jude Fawly
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

how can i copy a file from the location i found it on the pc using the JFileChooser into another location?

i will appreciate any help.
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
InputStream/OutputStream, or Reader/Writer.

You read the contents of the source file in smaller chunks, writing each chunk to the destination file.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be aware of the features java.io does not handle, like file permissions and ownership. Those will not necessarily be the same as in the original file. (And I won't even go into arcane stuff like Mac OS 9 files with resource forks, which also aren't handled.)
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our IO forum...
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15865
81
Android IntelliJ IDE Java Scala Spring
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't yet use Java 1.5, this article shows the code to do it.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15865
81
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
If you don't yet use Java 1.5, this article shows the code to do it.

The New I/O API (nio) was added in Java 1.4, so that code also works in Java 1.4.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Jesper: Good catch. With so many JDK versions it becomes hard to remember what got added when. I'm getting old
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!