Entry
How do I read a local file in NN calling into Java?
May 15th, 2000 08:46
Martin Honnen,
Your code needs to be trusted to request privilege to read files from
the local file system. Trust is given to local files (i.e. script
loaded via file: urls) or when signed or when the browser accepts
codebase principals to do so. See the entry on how to run trusted
scripts in NN:
The function reads in the content of a text file into a JavaScript
string:
function readFile (fileName) {
if (navigator.appName == 'Netscape' && navigator.javaEnabled) {
netscape.security.PrivilegeManager.enablePrivilege
('UniversalFileRead');
var br = new java.io.BufferedReader(new java.io.FileReader
(fileName));
var line;
var result = '';
while ((line = br.readLine()))
result += line + java.lang.System.getProperty('line.separator');
return result;
}
}
Example:
alert(readFile('C:\\autoexec.bat'))