Entry
How do I write a local file in NN calling into Java?
May 15th, 2000 08:59
Martin Honnen,
Your code needs to be trusted to request privilege to access the local
file system. See the entry on how to run trusted script in NN.
Here is a function that takes a filename and a string as an argument
and writes that string as the file content:
function writeFile (fileName, content) {
if (navigator.appName == 'Netscape' && navigator.javaEnabled) {
netscape.security.PrivilegeManager.enablePrivilege
('UniversalFileWrite');
var pw = new java.io.PrintWriter(new java.io.BufferedWriter(new
java.io.FileWriter(fileName)));
pw.print(content);
pw.flush();
pw.close();
}
}
Example:
writeFile('C:\\test.txt',
'All for Kibology.\nKibology for all.\n' +
'Scriptology at JavaScript.FAQTs.com')