/* File 64-bit encoding */
public static void Main (string[] args) {
byte[] Filebyte = Tobytearray (newFile);
String imgstr = new Base64encoder (). Encode (Filebyte);
}
/ * byte array to read the file */
Public Static byte[] Tobytearray (file file)throwsIOException {File f=file; if(!f.exists ()) { Throw NewFileNotFoundException ("File Not exists"); } bytearrayoutputstream Bos=NewBytearrayoutputstream ((int) f.length ()); Bufferedinputstream in=NULL; Try{ in=NewBufferedinputstream (NewFileInputStream (f)); intBuf_size = 1024; byte[] buffer =New byte[Buf_size]; intLen = 0; while( -1! = (len = in.read (buffer, 0, buf_size))) {bos.write (buffer,0, Len); } returnBos.tobytearray (); } Catch(IOException e) {e.printstacktrace (); Throwe; } finally { Try{in.close (); } Catch(IOException e) {e.printstacktrace (); } bos.close (); } }
Java reads a byte array of files