Copy link to clipboard
Copied
I'm having trouble reading a file into a string and can't figure out why.
var myFile = new File( '/path/to/my/file.xml' );
var myFileString = myFile.read();
alert( myFileString.length ); // displays 0
Does anybody know what could be going on here? It seems like such a simple operation.
Thanks.
Copy link to clipboard
Copied
I think I figured it out.
The file has be opened first with myFile.open('r');
Copy link to clipboard
Copied
Yes you are right.
Here is Javascript reference for file.Open()
var myFile = new File( '/path/to/my/file.xml' );
myFile.open("r");//for open real only
var myFileString = myFile.read();
myFile.close();
alert( myFileString.length);
Find more inspiration, events, and resources on the new Adobe Community
Explore Now