Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Below is the code I tried to write data into the file using JavaScript: 

var f = "sometextfile.txt";

writeTextFile(f, "Spoon")

writeTextFile(f, "Cheese monkey")

writeTextFile(f, "Onion")

function writeTextFile(afilename, output)

{

  var txtFile =new File(afilename);

  txtFile.writeln(output);

  txtFile.close();

}

It just prints the output to the console, not to a file. Can anyone tell me how to write data to file only using JS?

1 Answer

0 votes
by (19.7k points)

Check the below following points:

  1. If you try to write a file on a client machine it doesn’t work in cross-browsers. 

  2. If you try to write to the server, you can pass the text to the server and execute the code using server-side language. 

  3. If you want to store information on the client-side, check cooking. 

  4. If it’s local storage, use HTML5

Interested in Java? Check out this Java tutorial by Intellipaat. 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...