我有一个Web服务,返回PDF文件的base64编码字符串.
我想将此文件保存到SD卡.但是当我尝试这样做时,adobe reader会告诉我该文件已损坏.显然我没有妥善保存它.
byte[] pdfAsBytes = Base64.decode(resultsRequestSOAP.toString(),0);
File filePath = new File(Environment.getExternalStorageDirectory()+"/braodcasts.pdf");
FileOutputStream os = new FileOutputStream(filePath,true);
os.write(pdfAsBytes);
os.close();
resultsRequestSOAP.toString()看起来像这样:
JVBERi0xLjUNCiW1tbW1DQoxIDAgb2JqDQo8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAwIFIvTGFuZyhlbi1JRSkgPj4NCmVuZG9iag0KMiAwIG9iag0KPDwvVHlwZS9QYWdlcy9Db3VudCAxL0tpZHNbIDMgMCBSXSA+Pg0KZW5kb2JqDQozIDAgb2JqDQo8PC9UeXBlL1BhZ2UvUGFyZW50IDIgMCBSL1Jlc291cmNlczw8L0ZvbnQ8PC9GMSA1IDAgUj4+L0V4dEdTdGF0ZTw8L0dTNyA3IDAgUi9HUzggOCAwIFI+Pi9YT2JqZWN0PDwvSW1hZ2U5IDkgMCBSPj4vUHJvY1NldFsvUERGL1RleHQvSW1hZ2VCL0ltYWdlQy9JbWFnZUldID4+L01lZGlhQm94WyAwIDAgNTk1LjMyIDQxOS41Ml0gL0NvbnRlbnRzIDQgMCBSL0dyb3VwPDwvVHlwZS9Hcm91cC9TL1RyYW5zcGFyZW5jeS9DUy9EZXZpY2VSR0I+Pi9UYWJzL1M+Pg0KZW5kb2JqDQo0IDAgb2JqDQo8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvTGVuZ3RoIDE0ND4+DQpzdHJlYW0NCnicLY29CgIxEIT7hX2HKVVw3ewluUsr/qCdGLAQC5HzqlPU9wdjcKaaYZhvmZkWGwfnRD3ynclBix18l6T0TRJ1yGOZbY8thg+TYqip+6ct03mC6QV5z7Quhy+muYpWWWjhLEqKCClIYzBTCRHvnuk0w4PJuyi+Uk07MbRWsWV6+2F343XoE1ZPHJi+nDkiaw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