Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 528
Registered: ‎10-06-2009
My Device: 9800,BB Dev Alpha,z10 limited edition
My Carrier: Vodafone

how to read pdf file and convert it into byte[]

Hi I need to send .pdf , .docx files in the form of byte[] to the server. How can I implement that?

Rujuta Trivedi
Developer
Posts: 228
Registered: ‎10-01-2011
My Device: Passport

how to read pdf file and convert it into byte[]

[ Edited ]

 

 

This is a quick and dirty example. You need to add exception handling and you probably want to use a fixed buffer size so you don't gobble up all the heap.

 

FileConnection fc = (FileConnection) Connector.open(FQFN);

if (!fc.exists())
     throw new FileNotFoundException();

 

DataInputStream in = fc.openDataInputStream();
int len = in.available();
byte[] data = new byte[len];
in.read(data);

 

 

The file is now in the byte array  "data"

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to read pdf file and convert it into byte[]

Having got the data into byte format, the usual approach is to include this in an HTTP Post to that Server.  But how you do this depends on what the Server is expecting.  So you need to find out from your Server people what they need you to do.

 

Good luck.