Forum Discussion

ojo0608's avatar
ojo0608
Occasional Contributor
13 years ago

Write into Text file is not working properly.

Hi,



I am using TC for localization string things. Now, what I am doing is writing a string into a text file.

I used 'writeline' method but it works weirdly. 



Current language that I work on is Japanese and it looks fine on Log, but when I look at the file, some of last characters are missing.

E.g. I try to wirte 'はじめまして。お会いできて嬉しいです。' to file but TC write only はじめまして。おx. like this. last part are broken.



My TC version is 8.5.618.7.

It is issue or my script is wrong?



Thanks in Advance.

Jake

2 Replies


  • Hi Jake,



    It looks like you have faced a known problem with aqTextFile.WriteLine. It will be fixed in one of future TestComplete updates.



    As an alternative, you can try using the WriteLine method of the TextStream object.



    Also, one of TestComplete users suggested the following approach:





    function doSaveFile(strAbsoluteFilePath, strCharSet, strFileContents, blnOverwrite) {

        try {

            if (!strAbsoluteFilePath) {

                throw new Error(1, "Required parameter \"strAbsoluteFilePath\" was not defined");

            }

            if (!strCharSet) {

                throw new Error(2, "Required parameter \"strCharSet\" was not defined");

            }

            if (typeof strFileContents != "string") {

                throw new Error(3, "Required parameter \"strFileContents\" was not a string");

            }



            var objStream = new ActiveXObject("ADODB.Stream");

            objStream.Open();

            try {

                objStream.CharSet = strCharSet;

                objStream.WriteText(strFileContents);

                //objStream.SaveToFile(strAbsoluteFilePath, (blnOverwrite ? adSaveCreateOverWrite : adSaveCreateNotExist));

                objStream.SaveToFile(strAbsoluteFilePath, 1);

                return true;

            }

            catch (err) {

                throw new Error(err.number, "SaveToFile failed:\r\n" + err.description);

            }

            finally {

                objStream.Close(); // Always close the stream regardless of what happens

            }

            return false;

        }

        catch (err) {

            throw new Error(err.number, "Function doSaveFile() failed with parameters strAbsoluteFilePath=\"" + strAbsoluteFilePath + "\", strCharSet=\"" + strCharSet + "\", strFileContents=\"" + strFileContents + "\", blnOverwrite=\"" + blnOverwrite + "\". Message=\r\n" + err.description);

        }

    }









  • ojo0608's avatar
    ojo0608
    Occasional Contributor
    Awesome!! That works fine! 



    However, I hope that method will work soon, also.



    Thanks,

    Jake.