View Full Version : FileReader help

07-28-2009, 05:20 AM
I'm trying the following without a lot of luck. Its being called as a ECMAScript function from an application and I keep getting an error that readFile isnt known.

I'm not sure how to actually call the FileReader to read the file in, does anyone have any tidbits based on the code below?


function userLookup(strFileName,username){

var nNumLines = 0; //number of lines in file
var stringToConfirm = username; //will hold text from file
var document = new java.io.FileReader(strFileName);

nNumLines = document.FileReader.getNumLines();

for (var i=0; i<nNumLines; i++){

stringToConfirm += document.FileReader.getLine(i) + "\n";




function getLines(strFileName){

var stringDataFromFile = ""; //will hold string data in file

stringDataFromFile += document.FileReader.getLines();


Old Pedant
07-28-2009, 07:32 AM
Ummm...that code is a *MIX* of JavaScript and Java.

There's no such thing as java.io.FileReader or Packages.java.io in standard JavaScript/ECMAScript.

But I *THINK* there is a HUGE mistake there: You are creating a variable named document and that *HIDES* the normal global object of that name. Normally, when accessing Java from JavaScript, you use something like

document.AppletName.PublicMethodName( )

BUT that *must* be the standard global document object, not one you create.

It's been 8+ years since I used Java applets and "talked" to them from JavaScript (Java applets were to be the be-all, end-all that would save the Web...sure didn't turn out that way), so I don't trust my memory, too much. But the part about needing to use the global document object I'm pretty clear on.