This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund 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.
Farakh khan wrote:I think am using it here.
String encodedString = new sun.misc.BASE64Encoder().encode(fileContent);
thanks again for your prompt replies
But this states that you are using the class sun.misc.BASE64Encoder. And that is an internal proprietary API and may be removed in a future release. If Sun/Oracle wants to do it.
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:
Thanks Jasper from the bottom of my heart. Now I change the code like this:
Its still throwing the following error:
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35250
7
posted
0
Maybe you missed my earlier post:
fileContent is byte[], and you're trying to call its "getBytes" method?
And Jesper's:
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.
Farakh khan
Ranch Hand
Joined: Mar 22, 2008
Posts: 672
posted
0
Thanks all
The following piece of code solved my problem
Thanks again
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: 175: warning: BASE64Encoder is internal proprietary API and m ay be removed in a future release