Encode a file into Base64 format


	/**
	 * Method used for encode the file to base64 binary format
	 * @param file
	 * @return encoded file format
	 */
	private String encodeFileToBase64Binary(File file){
		String encodedfile = null;
		try {
			FileInputStream fileInputStreamReader = new FileInputStream(file);
			byte[] bytes = new byte[(int)file.length()];
			fileInputStreamReader.read(bytes);
			encodedfile = Base64.encodeBase64(bytes).toString();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return encodedfile;
	}

2 thoughts on “Encode a file into Base64 format

Comments are closed.