本地有张图片A.jpg
转UTF-8 存入A1.jpgA1.jpg 进行转码ASCII 存入A2.jpg ,但是显示不出图片
//测试2
public void test2(){
InputStream fis = null;
FileOutputStream fos = null;
try {
//读取某个文件转换成字符串
String str = FileUtil.readFileByBete("c:/MMpic/A.jpg", "UTF-8");
System.out.println(str);
byte[] b = new byte[1024 * 5];
fis = new ByteArrayInputStream(str.getBytes());
fos = new FileOutputStream("c:/MMpic/A1.jpg");
while(fis.read(b)!=-1){
fos.write(b);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try{
if(fis!=null) fis.close();
if(fos!=null) fos.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
//读取某个文件转换成字符串
public static String readFileByBete(String filePath,String charset){
FileInputStream br = null;
ByteArrayOutputStream outbyte = null;
try {
br = new FileInputStream(new File(filePath));
outbyte = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length=0;
while((length=br.read(buffer))!=-1){
outbyte.write(buffer, 0, length);
}
}catch(FileNotFoundException e1){
e1.printStackTrace();
}catch(IOException e2){
e2.printStackTrace();
}finally{
try{
br.close();
}catch(IOException e3){
e3.printStackTrace();
}
}
try {
return new String(outbyte.toByteArray(),charset);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}哪位大神帮俺看看
转UTF-8 存入A1.jpgA1.jpg 进行转码ASCII 存入A2.jpg ,但是显示不出图片
//测试2
public void test2(){
InputStream fis = null;
FileOutputStream fos = null;
try {
//读取某个文件转换成字符串
String str = FileUtil.readFileByBete("c:/MMpic/A.jpg", "UTF-8");
System.out.println(str);
byte[] b = new byte[1024 * 5];
fis = new ByteArrayInputStream(str.getBytes());
fos = new FileOutputStream("c:/MMpic/A1.jpg");
while(fis.read(b)!=-1){
fos.write(b);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try{
if(fis!=null) fis.close();
if(fos!=null) fos.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
//读取某个文件转换成字符串
public static String readFileByBete(String filePath,String charset){
FileInputStream br = null;
ByteArrayOutputStream outbyte = null;
try {
br = new FileInputStream(new File(filePath));
outbyte = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length=0;
while((length=br.read(buffer))!=-1){
outbyte.write(buffer, 0, length);
}
}catch(FileNotFoundException e1){
e1.printStackTrace();
}catch(IOException e2){
e2.printStackTrace();
}finally{
try{
br.close();
}catch(IOException e3){
e3.printStackTrace();
}
}
try {
return new String(outbyte.toByteArray(),charset);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}哪位大神帮俺看看
解决方案 »
- 一个关于hibernate的分页问题,急,望高人指点……只要您有方案即可得分
- 如何把oracle库中的数据导入到db2当中
- 哪位大哥有《java数据库应用程序编程指南》的源代码?
- webservice 的作业 各位大哥帮看看- JDeveloper SOAP/JDBC/XML Application
- 求助 struts配置
- 新来的,帮小弟一下。本地接口和远程接口的联系和区别!!!
- 求教关于Applet程序的最初级问题。
- oracle9i光盘 谁要
- 设计EJB的方法,请各位老大赐教
- Struts2使用开发模式遇到问题。本人刚学,希望各位能帮忙解决一下。感谢。
- faultCode: {http://schemas.xmlsoap.or
- 关于对象类型转换
你把图片的二进制信息转成字符串,然后再把字符串转成别的编码的二进制信息保存,你觉得这样的图片信息还正确吗?
fis = new ByteArrayInputStream(str.getBytes("UTF-8"));//按什么编码转成字符串的,再按什么编码转回去,否则图片信息肯定不一样了,也就是图片就不正确了,还怎么显示
服务器下发一个 图片地址 让客户端(sysbian) 访问这个地址 ,客户端返回的是utf-8 的字符串,我需要对这个字符串操作 转成图片。客户端程序不可以更改了。