File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 89
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: 19670
    
  18

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: 89
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: 89
thanks rob it is working
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

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