This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jpeg and mp3 doubt

 
vasu chowdary
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a small application i.e transfer files and directories from source to destination paths.I just use BufferedReader class and PrintWriter class but i got only .txt files were copied.how can i transfer any type of files like mp3,jpg.....
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just use InputStream and OutputStream, possible the Buffered versions.

Next, don't read lines but instead chunks. The basics, which works with every type of InputStream and OutputStream:

You can also choose to read byte per byte, but usually the above approach is a lot faster.

Don't be put off by the assignment in the while statement. It's a shorter way of writing the following:
 
vasu chowdary
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you mean jpeg file can be read and write using stream classes like text files?
 
vasu chowdary
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks rob it is working
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vasu chowdary:
do you mean jpeg file can be read and write using stream classes like text files?

The Stream classes can be used for any type of file, because it just reads and writes the bytes of the file. It doesn't look at what those files mean.

For text files, the Reader and Writer classes are better since they are able to convert the bytes into actual characters. While for simple ASCII text files you won't notice much difference, you will feel differently when reading unicode text files.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic