
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Reading a byte array from a json file and then convert it into xlsx file
I have a small use case wherein I need to fetch an excel file from an api response. The api response is of json format and I need to
1.) read the json element which contains byte array (byte[])
2.) convert the byte array to a excel file.
I have set the data type as byte[] for my JSON coloumn containing the byte array.
The output.file_contents contains the byte array which I am sending to java routine to convert it into a xlsx file.
The code for my tjava is quite a simple one.
System.out.println(input_row.file_contents);
Write.ByteArrayToFile(input_row.file_contents, context.finalPath) ;
The for my routine is
package routines;
public class Write {
public static void ByteArrayToFile(byte[] input, String filepath) {
try
{
java.io.File fp = new java.io.File(filepath);
java.io.FileOutputStream fos = new java.io.FileOutputStream(fp);
fos.write(input);
fos.close();
}
catch(Exception err)
{
err.printStackTrace();
}
}
}
The talend code is executing and also creating an xlsx file at desired location. However, everytime when I open my excel it gives an error as
Any help in this will be really apprciated. I think the isse is how I am reading the json file. However when I am trying to print the byte array I can properly see it values as

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To test your routine code, you can use tFileInputRaw to read the whole file as a bytes array.
Regards
Shong
