AV

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 

by Amol Patil
Posted on Fri, 02/17/2012 - 21:27

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

0
by Allen V. Author
Posted on Fri, 02/17/2012 - 23:01

Thank You Amol!  This works perfect!

I was able to come up with my own solution below, but yours seems cleaner.  I ended up looping and reading one byte at a time.  Problem with ARIS script is not being able to define data type and size.

function getBytesFromFile(inputPath, inputFile){
    // Define file object to store file info
    var file = new java.io.File(inputPath, inputFile);
    // Define array to store byte array info for data 
    var bytes = new Array();
    // Define data input stream object that we will read
    var is = new java.io.DataInputStream(new java.io.FileInputStream(file));
    // Loop to read each byte from file until the end of file
    for (var index = 0; index < file.length(); index++) {
        bytes[index] = is.readByte();
    }
    return bytes;
}

Regards,

Allen

0
by Allen V. Author
Posted on Thu, 02/23/2012 - 22:22

In reply to by tobias.maier

Hello,

 

After I read the file, I wish to delete it from the network directory.  I thought it would be easy enough to do:

file.delete();

But that does not work in ARIS script.  I even tried just to rename it to some other filename, but that method doesn't seem to work either.

Is this possible to do from within a report script?



Regards,

Allen

0
by Amol Patil
Posted on Sat, 02/25/2012 - 16:43

Hi Allen,

Try using

Context.deleteFile(filepath);

Make sure you have delete access to that network location.

Thanks,

Amol Patil

0

Featured achievement

Rookie
Say hello to the ARIS Community! Personalize your community experience by following forums or tags, liking a post or uploading a profile picture.
Recent Unlocks

Leaderboard

|
icon-arrow-down icon-arrow-cerulean-left icon-arrow-cerulean-right icon-arrow-down icon-arrow-left icon-arrow-right icon-arrow icon-back icon-close icon-comments icon-correct-answer icon-tick icon-download icon-facebook icon-flag icon-google-plus icon-hamburger icon-in icon-info icon-instagram icon-login-true icon-login icon-mail-notification icon-mail icon-mortarboard icon-newsletter icon-notification icon-pinterest icon-plus icon-rss icon-search icon-share icon-shield icon-snapchat icon-star icon-tutorials icon-twitter icon-universities icon-videos icon-views icon-whatsapp icon-xing icon-youtube icon-jobs icon-heart icon-heart2 aris-express bpm-glossary help-intro help-design Process_Mining_Icon help-publishing help-administration help-dashboarding help-archive help-risk icon-knowledge icon-question icon-events icon-message icon-more icon-pencil forum-icon icon-lock