byte[] serObj = getBytesFromFile(file);
final byte[] CLRF = { '\r', '\n' };
Base64 encoded = new Base64 (72,CLRF);
System.out.println(encoded.encodeBase64String(serObj));
I am having problems formatting the output, which currently displays as a single line, and not according to the args in constructor. It is supposed to be a line with 72 chars and followed by CLRF and the next line. Can someone point out what’s wrong with the code? Also, how could I manually append/add a newline char within a String? I tried using a char counter, but I am stuck on how to add the \n once the counter reaches the 72nd char.
public static int count(Reader in) throws IOException {
char[] buffer = new char[4096];
int count = 0;
int len;
while((len = in.read(buffer)) != -1) {
count += len;
}
return count;
}
The
encodeBase64String(byte[])method you are calling is astaticmethod, so theBase64instance that you created is not being used by the method call.You should be using the
encodeToString(byte[])method, which is an instance method.