Hello,
I am trying to read an excel file from a network folder. I am using standard Java DataInputStream to read the file and store the value in a byte array. How can I declare a variable of type byte array and specify the size of this byte array?
function getBytesFromFile(inputPath, inputFile){
var file = new java.io.File(inputPath, inputFile);
var bytes = new Array;
var dis = new java.io.DataInputStream(new java.io.FileInputStream(file));
dis.read(bytes);
dis.close();
return bytes;
}The above code does not return any value.
Standard way in java is to declare the variable like this:
byte bytes[] = new byte[(int)file.length()];
But that doesn't seem possible in ARIS script.
Thanks for any help.
Regards,
Allen
Amol Patil on
Hi Allen,
Hope this helps you
function getBytesFromFile(inputPath, inputFile) { var file = java.io.File(inputPath, inputFile); var fileInputStream = java.io.FileInputStream(file); var byteArrayOutputStream = java.io.ByteArrayOutputStream(); while (fileInputStream.available()) { byteArrayOutputStream.write(fileInputStream.read()); } var bytes = byteArrayOutputStream.toByteArray(); fileInputStream.close(); byteArrayOutputStream.flush(); byteArrayOutputStream.close(); return bytes; }Regards,
Amol Patil