2

I am trying to convert an arbitrary Xml Document to a byte array so that it can be encoded using Base64. Can anybody help me with how to go about this. Also, what's the easiest api to use for base64 encoding in Java?

Thanks.

1
  • What have you tried so far? Have you looked at any documentation yet? Show us some code for things you have tried. Commented Nov 6, 2012 at 23:58

1 Answer 1

1

The easiest API for base64 encoding is probably Commons Codec.

Sign up to request clarification or add additional context in comments.

4 Comments

using the api it is done something like this: byte[] encode = Base64.encode(unencodedString.getBytes()); String encodedString = new String(encode);
This is only an answer because of @SeanF. Normally I would flag this as a comment
Thanks guys...here's what I came up with. Still doesn't work.
public static void main(String[] args) { try{ File f = new File("servers.xml"); FileInputStream fis = new FileInputStream(f); byte [] ba = new byte[(int)f.length()]; fis.read(ba); } catch (Exception e){ System.out.println("exception occurred ==>"+e); } byte [] code = Base64.encodeBase64(ba); }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.