OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

"File is not defined" error in javascript while executing from node.js command prompt

  • Thread starter Thread starter rstalekar
  • Start date Start date
R

rstalekar

Guest
I have a javascript in which I try to read a file and just print it on the console , however it gives "File is not defined" error inspite of the file test.txt being in the same path Following is the code snippet.

Code:
var txtFile = "test.txt";
var file = new File(txtFile);
file.open("r");
var str = "";
while (!file.eof) {
    str += file.readln() + "\n";
}
console.log(str);
file.close();

<p>I have a javascript in which I try to read a file and just print it on the console , however it gives "File is not defined" error inspite of the file test.txt being in the same path Following is the code snippet.</p>

<pre><code>var txtFile = "test.txt";
var file = new File(txtFile);
file.open("r");
var str = "";
while (!file.eof) {
str += file.readln() + "\n";
}
console.log(str);
file.close();
</code></pre>
 

Latest posts

Top