Base64编码的InputStream为String [英] Base64 InputStream to String
问题描述
我一直在试图让一个输入流中读取一个文件,ISA纯文本,并镶嵌着一些图像和其他文件的base64
,并在String再写一遍。但是,保持编码,我的意思是,我想在字符串是这样的:
I have been trying to get an input stream reading a file, which isa plain text and has embeded some images and another files in base64
and write it again in a String. But keeping the encoding, I mean, I want to have in the String something like:
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJCIf
IiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8SDc9Pjv/2wBDAQoLCw4NDhwQEBw7KCIoOzs7Ozs7
我一直在试图与类 Base64InputStream
多由包为 org.apache.commons。codeC
但我不能fiugure出来。任何形式的帮助将是非常美联社preciated。在此先感谢!
I have been trying with the classes Base64InputStream
and more from packages as org.apache.commons.codec
but I just can not fiugure it out. Any kind of help would be really appreciated. Thanks in advance!
修改
使用阅读器code海贼王:
Piece of code using a reader:
BufferedReader br= new BufferedReader(new InputStreamReader(bodyPart.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
br.close();
获取结果是这样的: .DIC; YUC((;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;雅@@雅
推荐答案
我找到了解决方案,通过这个帖子的启发<一个href=\"http://stackoverflow.com/questions/2764504/getting-base64-content-string-of-an-image-from-a-mimepart-in-java\">getting从Java中的mimepart图像的base64内容字符串
I found the solution, inspired by this post getting base64 content string of an image from a mimepart in Java
我觉得这是一种愚蠢的去code和EN code再次的base64 code,但我发现来管理这一问题的唯一途径。如果有人能给出一个更好的解决方案,这将是也确实AP preciated。
I think it is kind of stupid decode and encode again the base64 code, but it is the only way I found to manage this issue. If someone could give a better solution, it would be also really appreciated.
感谢
这篇关于Base64编码的InputStream为String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!