Problem to write binary data with writeSync



Hello good people, I wanted to encrypt some text in nativescript. After decryption when I was trying to write the bytearray data into a file with writeSync I was getting the following error message:
java.lang.Exception: Failed resolving method write on class

And here is my code:

    const fileText = "A string to test";
    const  secretKey = "HelloWorld";
    const encryptedData = CryptoJS.AES.encrypt(fileText , secretKey);
    const decryptedData = CryptoJS.AES.decrypt(encryptedData, secretKey);
    const decryptedDataText = decryptedData.toString(CryptoJS.enc.Utf8);
    const data = base64js.toByteArray(decryptedDataText);

    this.newFile = this.folder.getFile((this.fileName || "output") + ".txt");
    this.newFile.writeSync(data, (err) => {
        // console.log(err);

Please help me out from this problem


JavaScript’s byte array !== Java byte array, it won’t be auto casted in this case. Since it’s just a string why don’t you just pass decryptedDataText to writeText?


I need binary data into the new txt file instead of string