| |
import java.io.*;
import javax.mail.internet.MimeUtility;
|
| |
public static void main(String[] args) {
|
| |
 |
//initialize input and output file name
String strInputFileName = "enter file name (to encode) here";
String strOutputFileName = "enter output file name here";
rawFileToBase64(strInputFileName,strOutputFileName);
|
| |
}
|
| |
public static boolean rawFileToBase64 (String inFile, String outFile) { |
| |
try { |
| |
 |
// initialize inputFile
FileInputStream fin = new FileInputStream(inFile);
BufferedInputStream bis = new FBufferedInputStream(fin);
// initialize outputFile
FileOutputStream fos = new FileOutputStream(outFile);
OutputStream os = MimeUtility.encode(fos,"base64");
BufferedOutputStream bos = new BufferedOutputStream(os);
byte data[] = new new byte[1024];
int len;
// read the buffered stream
while(bis.available()>0)
{
len = bis.read(data);
bos.write(data,0,len);
}
bos.close();
bis.close();
|
| |
} catch (Exception e) { |
| |
System.out.println("Unable to encode the contents of the request file."+ e);
}
|
| |
}
|