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);      
        }
  • 相关阅读:
    java基础篇6之代理
    JavaWeb 过滤器应用之页面静态化
    JavaWeb 之过滤器
    JavaWeb 之监听器
    分页
    Linux 入门
    多条件组合查询
    Service 事务(JdbcUtils 升级)
    BaseServlet 介绍
    dbUtils 工具类介绍
  • 原文地址:https://www.cnblogs.com/v-weiwang/p/4990564.html
Copyright © 2011-2022 走看看