將圖片轉化為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是真麻煩啊~~


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM