我使用的是一个需要能够转换为Base64字符串的PDF文件的InputStream。 Base64字符串格式不正确,因为当我解码PDF文件时将无法打开。有更好的方法吗?
PDFString = fromStream(is);
String encoded = DatatypeConverter.printBase64Binary(PDFString.getBytes());
public static String fromStream(InputStream in) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder out = new StringBuilder();
String newLine = System.getProperty("line.separator");
String line;
while ((line = reader.readLine()) != null) {
out.append(line);
out.append(newLine);
}
return out.toString();
}