Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

Copying files

Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, I'm working on a program that involves having a music library. I want to have the songs be imported into a file that will be accessible by the program (in a folder inside the folder containing the program's class file), but I don't want to just move the files. How would I do this? I would be moving audio files.
author and iconoclast
Posts: 24204
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jacob,

Copying a file in Java is very simple. You just

1) Open the old file for reading,
2) Open the new file for writing
3) Read each byte from the old file and
4) Write it into the new file
5) Close both the files.

You can either do this with a FileInputStream/FileOutputStream pair, or if you want to get fancy, you can use FileChannels. Either way, it's basically the same.

Since it's binary data, be sure to read and write bytes, not chars.
He's dead Jim. Grab his tricorder. I'll get his wallet and this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    Bookmark Topic Watch Topic
  • New Topic