Files


To work with files, you must use the type java.io.File. Also, the program includes support for the library apache.commons.io, which will simplify the work with files.

var File = Java.type('java.io.File');
var FileUtils = Java.type('org.apache.commons.io.FileUtils');

var myFile = new File('helloWorld.txt');

system.println('Is file exist? - ' + myFile.exists());
system.println('');

if(!myFile.exists()){
    FileUtils.write(myFile,'Hello world','UTF-8');
}

system.println('file content:');
system.println(FileUtils.readFileToString(myFile,'UTF-8'));

File, FileUtils