on 01-16-2009 3:43 AM
Dear all,
i have this
byte[] att_content = new byte[255];
att_content = attach[0].getResource();
i have this..attach[0].getResource() which will return me the contents of the attachment attached to the adobe form..cut it short..it is of byte[] type..so i declared a byte[] att_content to hold it..
after i get this att_content,i need to send it back to my SAP system and create the attahcment to a PR...i get to do the attahcment, but when i try to open the attached file,(a MS WORD doc).the wording in the MS word all become unreadable...i think is the problem of the byte[] i send in.....
any idea how to get ti fix? thank you
Hi,
File file = new File("C:\abc.doc")// pass the full path here and then use file in the below code
public static byte[] getBytesFromFile(File file) throws IOException {
InputStream is = new FileInputStream(file);
I
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Joan,
I think you cannot directly pass the file to byte array. and thats why you are getting the unreadable format.
Please use the below method which returns byte array.
// Returns the contents of the file in a byte array.
public static byte[] getBytesFromFile(File file) throws IOException {
InputStream is = new FileInputStream("Pass here the resource path");
// Get the size of the file
long length = file.length();
// You cannot create an array using a long type.
// It needs to be an int type.
// Before converting to an int type, check
// to ensure that file is not larger than Integer.MAX_VALUE.
if (length > Integer.MAX_VALUE) {
// File is too large
}
// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];
// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < bytes.length
&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}
// Ensure all the bytes have been read in
if (offset < bytes.length) {
throw new IOException("Could not completely read file "+file.getName());
}
// Close the input stream and return bytes
is.close();
return bytes;
}
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
94 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.