Skip to content

Instantly share code, notes, and snippets.

@eggie5
Created December 18, 2010 21:56
Show Gist options
  • Save eggie5/746911 to your computer and use it in GitHub Desktop.
Save eggie5/746911 to your computer and use it in GitHub Desktop.
encode arbitrary file to base64 string (java)
String s= new String();
int BUFFER_SIZE = 4096;
byte[] buffer = new byte[BUFFER_SIZE];
InputStream input = new FileInputStream(args[0]);
OutputStream output = new Base64OutputStream(new FileOutputStream(args[1]));
int n = input.read(buffer, 0, BUFFER_SIZE);
while (n >= 0) {
output.write(buffer, 0, n);
n = input.read(buffer, 0, BUFFER_SIZE);
}
input.close();
output.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment