Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

copying files  RSS feed

 
Csaba Kassitzky
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone!

This might be a very noob question, but i still got problems with it:
How can i copy a file if the source and destination address is given?
Copying from line to line doesn't work on some files like pictures. How can i copy then?
Thanks!
 
Rajagopal Manohar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Csaba Kassitzky:
Copying from line to line doesn't work on some files like pictures. How can i copy then?
Thanks!


Looks like you are using the Readers and Writers of the IO API to do the copying

Using the Input/Output Stream's should do the trick in your case as the charecter encodings are preserved as is

Look at BufferedInputStream and BufferedOutputStream
That should help

-Rajagopal
[ December 07, 2005: Message edited by: Rajagopal Manohar ]
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15861
81
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this:
The Java Developers Almanac - Copying One File to Another
 
Csaba Kassitzky
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This seems nice, but what should i do, if my source is actually a web address(URL class)? I used this so far:

How can i modify this one?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're not using two files, then using the NIO classes here would get somewhat more complex. It's probably easier to stick to java.io classes instead. Rajagopal's post gave good advide for this. To copy files without modification, there's never any reason to use classes with Reader or Writer in their names. You want things that say InputStream and OutputStream. Here is an example that's close to what you want.
 
Csaba Kassitzky
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is good, but how do i put an URL into the sourcefile?

This is what i have so far from it:
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You change your code so that it isn't expecting filenames as its parameters, and so that it can use things other than files. Perhaps like this:Then to call that:
 
Csaba Kassitzky
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help!
They seem to work now.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!