zoukankan      html  css  js  c++  java
  • java图片转byte转string

    第一种:原始乱码:

    public static void main(String[] args) throws IOException {
                File imgFile = new File("d:\1.jpg");   
                FileInputStream fis = new FileInputStream( imgFile );   
                byte[] bytes = new byte[fis.available()];   
                fis.read(bytes);   
                fis.close();   
                String imgStr = new String(bytes);   
                System.out.println( imgStr);      
        }

    第二种:完整字节:

    public String byteToString(byte[] buf){
            String str1="";
            StringBuilder sb=new StringBuilder(str1);
            for (byte element: buf )
            {
            sb.append(element);
            }
            str1=sb.toString();
            return str1;
        }
        public static void main(String[] args) throws IOException {
                File imgFile = new File("d:\1.jpg");   
                FileInputStream fis = new FileInputStream( imgFile );   
                byte[] bytes = new byte[fis.available()];   
                fis.read(bytes);   
                fis.close();   
                String imgStr = new Byte().byteToString(bytes);   
                System.out.println( imgStr);      
        }
  • 相关阅读:
    Windows 下搭建FTP服务器
    PHP的异常以及异常存在的意义
    IE兼容性
    YII插件
    PHPCMS部件
    YII学习笔记
    MAC下PHP开发
    iframe
    centos+apache+mod_ssl
    xcode快捷键
  • 原文地址:https://www.cnblogs.com/v-weiwang/p/4990564.html
Copyright © 2011-2022 走看看