当前位置: 代码迷 >> Java相关 >> .docx文件转base64 再转回.docx文件 乱码有关问题 求帮助
  详细解决方案

.docx文件转base64 再转回.docx文件 乱码有关问题 求帮助

热度:1258   发布时间:2013-02-25 21:48:04.0
.docx文件转base64 再转回.docx文件 乱码问题 求帮助
C# code:
//读取文件 得到byte[]
byte[] btFile = FileToBinary(filePath + txtTrack.Text+".docx");
//byte 转 base64
String filedatas = System.Convert.ToBase64String(btFile);
//XLAjax 传filedatas到Java
  ...


Java code:
try{
//filedatas base64字符串 转byte[]
 byte[] buffer = new BASE64Decoder().decodeBuffer(filedatas);
 FileOutputStream out = new FileOutputStream(filePath);
 out.write(buffer);
 out.close();
}catch(Exception e){}


现在问题就是 生成的 .docx 乱码

------解决方案--------------------------------------------------------
如果你验证过Java和C#的BASE64算法互通没有问题的话,无非就是传输的时候出问题了。
如果作为Get请求传,那么即便是Base64,在空格等特殊字符传输时应该有问题。
  相关解决方案