zoukankan      html  css  js  c++  java
  • 将图片转化为base64编码字符串

    pom依赖

    
    		<dependency>
    			<groupId>org.ops4j.base</groupId>
    			<artifactId>ops4j-base-net</artifactId>
    			<version>1.5.0</version>
    		</dependency>
    
    
    
    import org.ops4j.net.Base64Encoder;
    
            /**
    	 * 根据图片地址转换为base64编码字符串
    	 * @param imgFile 图片文件名称
    	 * @return
    	 * @author xuehp
    	 * @date 2019年6月4日 下午12:28:40
    	 */
    	public static String getImageStr(String imgFile) {
    		InputStream inputStream = null;
    		byte[] data = null;
    		try {
    			inputStream = new FileInputStream(imgFile);
    			data = new byte[inputStream.available()];
    			inputStream.read(data);
    			inputStream.close();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		// 加密
    		return new String(Base64Encoder.encode(data));
    	}
    

    话说java是真麻烦啊~~

  • 相关阅读:
    迭代器和生成器
    20.03.23作业
    装饰器
    集合
    元组类型
    字典类型
    列表类型
    字符串类型
    for循环
    深浅copy与while循环
  • 原文地址:https://www.cnblogs.com/xuehuiping/p/12056344.html
Copyright © 2011-2022 走看看