permaculture playing cards*
The moose likes I/O and Streams and the fly likes jpeg and mp3 doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "jpeg and mp3 doubt" Watch "jpeg and mp3 doubt" New topic
Author

jpeg and mp3 doubt

vasu chowdary
Ranch Hand

Joined: Mar 15, 2008
Posts: 88
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

Joined: Oct 27, 2005
Posts: 19538
    
  16

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:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
vasu chowdary
Ranch Hand

Joined: Mar 15, 2008
Posts: 88
do you mean jpeg file can be read and write using stream classes like text files?
vasu chowdary
Ranch Hand

Joined: Mar 15, 2008
Posts: 88
thanks rob it is working
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19538
    
  16

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jpeg and mp3 doubt
 
Similar Threads
How to transferring Files with Bluetooth
designating mp3s as podcasts
How To Make Search Engine
Transfer big files as byte array over network
Ubuntu Question