JAVA读取并将图片转换成String

来源:互联网 发布:香港中老年人奶粉知乎 编辑:程序博客网 时间:2024/05/29 16:38

private static String readString3()

 {

  String str = "";
  String path = "C:/Users/J2EE/Desktop/Q_ITOffer_Chapter12/WebContent/images/huawei.jpg";
  File file = new File(path);

  try {

   FileInputStream in = new FileInputStream(file);

   // size 为字串的长度 ,这里一次性读完

   int size = in.available();

   byte[] buffer = new byte[size];

   in.read(buffer);

   in.close();

   str = new String(buffer, "GB2312");

  } catch (IOException e) {

   // TODO Auto-generated catch block

   return null;

  }

  return str;
 }

0 0
原创粉丝点击