日期:2014-05-20  浏览次数:20808 次

.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,在空格等特殊字符传输时应该有问题。