一个文件被转换成base64编码的字符串后,又用utf-8的编码形式写入到一个xml文件里,如果由xml文件里面的字符串还原为原来的文件? 1. 读完所有图片数据后做encode2. 读完节点的数据后做decode3. 注意读取xml文件的编码方式, 可能需要使用utf-8方式读入 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我是用 dom4j的XMLWriter把文件写到硬盘上的,用DOMParser读入文件,然后再获取结点的值的, 这样做,有问题么? 应该没有问题,读出来后,用decoder变成二进制数组,再生成图片就行. 55555 可是就是不行啊。。1。encode:FileInputStream fileForInput = new FileInputStream("d:/test.jpg");String content = new String(); byte[] bytes=new byte[fileForInput.available()]; fileForInput.read(bytes); content=new sun.misc.BASE64Encoder().encode(bytes); //具体的编码方法 fileForInput.close();2。写文件:dom4j.XMLWriter output = new XMLWriter( new FileOutputStream(FileName)); output.write( document ); output.close(); 3。读取出对应结点的值后decode,用DOMParser读入文件的:byte[] result =new sun.misc.BASE64Decoder().decodeBuffer(FileContent); RandomAccessFile inOut = new RandomAccessFile(Root + "/" + FileName, "rw");inOut.write(result);不知道是哪个地方出了问题? 没办法还原?不会吧?base64编码范围比ascii都要小,用utf8其实和ascii一莫一样,至于不能还原肯定是base64解码器的问题,和xml编码无关 可以肯定不是编码器和解码器的问题,我测试过了,把一个图片文件读入进行base64编码后,马上解码生成文件是ok的也许是写文件和读文件的时候有些地方不妥高手指点啊 检查过了,发现改用dom4j读入文件的话,就可以还原图片难道用dom4j生成的文件,用DomParser读取就会出问题???可是我必须要用DomParser啊哪位高手能指点一下啊? java 怎么将十六进制变为相同内容的byte 请问如何用htmlparser得到某网页中所有的邮箱地址 ? 仓库系统 算法问题 输出问题,后台快捷键响应,回答者皆送分 怎么安装J2SE 1.5 SDK 特大喜讯::: 有奖征文>>怎样在java程序中传递字报表参数???? applet的应用及速度问题??????? 请问Java怎样能读取共享文件夹里的东西。 求书,虽然和JAVA只有一半关系,还是问在这里! help,help!!! 求eclipse关于plugin和swt开发的电子书籍。英文的也可。。。 高手帮忙解答关于组件监听的问题?小弟先谢了!
用DOMParser读入文件,然后再获取结点的值的, 这样做,有问题么?
FileInputStream fileForInput = new FileInputStream("d:/test.jpg");
String content = new String();
byte[] bytes=new byte[fileForInput.available()]; fileForInput.read(bytes); content=new sun.misc.BASE64Encoder().encode(bytes); //具体的编码方法
fileForInput.close();
2。写文件:
dom4j.XMLWriter output = new XMLWriter( new FileOutputStream(FileName));
output.write( document );
output.close(); 3。读取出对应结点的值后decode,用DOMParser读入文件的:byte[] result =new sun.misc.BASE64Decoder().decodeBuffer(FileContent);
RandomAccessFile inOut = new RandomAccessFile(Root + "/" + FileName, "rw");
inOut.write(result);不知道是哪个地方出了问题?
可是我必须要用DomParser啊哪位高手能指点一下啊?