我有一个 hl7 文件,其中包含从编码的 pdf 派生的 base64 字符串。
是否可以从该 base64 重新创建 pdf?
pdf to base64 --> ok
----------------------------
base64 to pdf --> is this possible?
最佳答案
这是可能的。您可以使用 sun.misc.BASE64Decoder。
示例:
import java.io.*;
import sun.misc.BASE64Decoder;
/**
* Kax7ux
*
*/
public class App
{
public static void main( String[] args )
{
String encodedBytes = "yourStringBase64";
try {
BASE64Decoder decoder = new BASE64Decoder();
byte[] decodedBytes;
FileOutputStream fop;
decodedBytes = new BASE64Decoder().decodeBuffer(encodedBytes);
File file = new File("path/file.pdf");
fop = new FileOutputStream(file);
fop.write(decodedBytes);
fop.flush();
fop.close();
System.out.println("Created");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
关于java - 是否可以从 Base64 字符串创建 pdf 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34890501/