This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
Ofcourse downloading the JAR and putting it in your classpath is not enough. You'll also need to change your program to make use of the Base64 codec that's in the JAR file, instead of using class sun.misc.BASE64Encoder.
You get the error because sun.misc.BASE64Encoder is an internal API of the JDK. It's not part of the official public Java API, so you are not supposed to be using it. There's no guarantee that in a future Java update this class will still exist, and in other Java implementations (for example IBM's JVM) this class doesn't exist.
fileContent is a byte in your code, and in line 5 you are calling the method getBytes() on it. That is not going to work, because a byte doesn't have a getBytes() method.
Also, there are more reasons why this will not work. The method read() of class FileInputStream, that you are calling in line 3, does not necessarily read the entire content of the file. It might just read the first few bytes, or even nothing at all. Just calling read() the way that you are doing is not a good way to read the content of a file into a byte array.
As I already mentioned above, this is not guaranteed to work correctly:
This will not always read the entire content of the file into the byte array. The API documentation of FileInputStream.read(byte b) explains:
API documentation wrote:
Reads up to b.length bytes of data from this input stream into an array of bytes. This method blocks until some input is available.
Returns: the total number of bytes read into the buffer, or -1 if there is no more data because the end of the file has been reached.
Note that it might not read the entire file. It might read only the first 10 bytes, for example. Note that the method returns the number of bytes read. To read an entire file into a byte array, you need to call this method in a loop until it returns -1, or until you've filled the whole array. Like this: