• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

copying files

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Marshal
Posts: 27667
89
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help!
They seem to work now.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic