The code in your example is not going to work properly with JPG files.
There are two kinds of I/O classes in
Java: there are streams (InputStream and OutputStream) and readers/writers.
Streams are for dealing with binary data.
Readers and writers are for dealing with text files. In your example, you're using a BufferedReader and a FileWriter, which are both classes designed to be used for reading and writing text files, to copy a JPG file, which is not a text file. You're also trying to store the binary data in a
String, which is not designed for storing arbitrary binary data.
If you want to be able to copy arbitrary files (binary or text), use streams, not readers/writers. If you're using Java 7, then copying a file is very simple:
If you want to be able to load image files so that you can for example display them in a GUI, then Java's
ImageIO API is useful for that. Note that it doesn't support all image file formats, just a few basic ones (including JPG and PNG).
Another remark:
Never catch exceptions and ignore them, as you're doing in lines 16 and 17 of your code. When an exception occurs, you'll not see anything and you won't know that something went wrong. At least print an error message when you catch an exception. For example: