Read the image file into the string and perform Base64 encryption

xiaoxiao2021-03-06  42

. Import java.io *; import sun.misc *; public class ReadBase64Pic {private String base64str = null; private String picname =. "D: /1.gif"; // picture source FileInputStream file; private ReadBase64Pic () {/ / System.out.println ("init");} private void read () {int N = 0; try {file = new fileinputstream (picname); while ((n = file.available ())> 0) {byte [] b = new byte [n]; int result = file.read (b); if (result == - 1) Break; base64str = new string (b); sun.misc.base64encoder eNCode = new sun.misc. Base64encoder (); Base64Str = Encode.Encode (Base64Str.getBytes ()); // Encrypted} system.out.println (Base64Str);} catch (Exception E) {System.out.Println ("Read Pic File Error") }}

Private void write () {Try {fileoutputstream fo = new fileoutputstream ("d: /1.jsp"); fo. :te64str.getbytes ()); system.out.write ('/ t'); flush ();} Catch (exception e) {system.out.println ("Write Method Error IS" E.TOString ());}} public static void main (String [] args) {readbase64pic pic = new readbase64pic () Pic.read (); pic.write ();}}

转载请注明原文地址:https://www.9cbs.com/read-60841.html

New Post(0)