Batch Job to Append Text to a .TXT file


When I use TextIo in a Bach Class to append text to a .txt file, I get the following error

Error executing code: TextIo object not initialized.

Does this have something to do with where the code should run (client/server tier)? Currently my class runs on server.

If TextIo should run in client tier, what is the alternative code so that I can perform the same task is server tier?

Thanks so much.

Taken from help: If an attacker can control input to the new method, a security risk exists. This method runs under Code Access Security. Calls to this method on the server require permission from the FileIOPermission Class. Ensure that the user has development privileges by setting the security key to SysDevelopment on the control that calls this method.

Have you assert the permission in your code?

Hi Fabricio,

Yes I placed an assert before I initialized my TextIo object. Here is my code.

void writeError(str _fileName, str _line, Counter _lineNumber)



FileIOPermission perm;

TextIo errorFile;

Container con;

str mode;

Set permSet;



perm = new FileIOPermission(_fileName,#IO_append);


errorFile = new TextIo(_fileName,#IO_append);





Thank you.

So I supposed you run this without batch for testing purposes, did it work?

Hi Fabricio,

Yes it did work without batch. Actually, I ran the code using a job without assert and it still works. I only encounter the error when I run the code in batch.

Are you sure your class runs on server tier?

Hi Fabricio,

Yes, my class’ Run on property is set to server.

A class with only a main method set to run on server works ok.

public static server void main(Args args)
Filename filename = “d:\tmp\test.txt”;
TextIO text;
//new FileIOPermission(filename, “w”).assert();
text = new TextIO(filename, “w”);
text.write(“This is something”);

If you comment the assertion you will get an error because you need the assertion on server, therefore I conclude that your class is not running on server. Make sure your class is running on server, do the assert and it should work.

Hi Fabricio,

I found out the reason why I get the error message (TextIO not initialized), and that is because I was using an invalid filename.

TextIO is not working when the class is executed in batch. Instead, I used System.IO.File to read/write a file.

Thank you.

Does TextIO not work at all in Batch??!?