0 votes
1 view
in Java by (9.2k 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 (19k 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. 

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...