First let's start with the warning. You shouldn't use classes from packages that start with com.sun, sun or sunw. These classes are for JVM internal use only, and can be modified or removed as Oracle feels fit. Check out Apache Commons instead, they have a base64 class in their Codecs library.
Right, to the errors.
String has method replace(CharSequence, CharSequence). StringBuilder and StringBuffer only have method replace(char, char) - there is no method for replacing full Strings. The solution in this case is quite simply - replace in the line first, then append the line: