Explain how to read and write a file using javascript?



Explain how to read and write a file using javascript?..

Answer / Sumit Kumar Srivastav

"Reading and writing files in JavaScript can be done using the FileReader API. To read a file, you can create a new FileReader object, set its onload event with a callback function, call the readAsText() method to read the file as text, and access the contents through the onload event's target. Here's an example: let reader = new FileReader(); reader.onload = function (event) { console.log(event.target.result); }; reader.readAsText(file); To write a file, you can create a new Blob object with the desired content, create a new File object using a user-provided name and the Blob, and use the saveAs() method to download the file: let blob = new Blob([content], { type: "text/plain" }); let file = new File([blob], "myFile.txt", { type: "text/plain" }); saveAs(file);"

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More JavaScript Interview Questions

I need project details about WEB CONTENT FILTERING USING NEURAL NETWORKS and how to explain it....plz help me in this topic.....

1 Answers  


What is innertext javascript?

1 Answers  


How do I find javascript?

1 Answers  


What is Minification

1 Answers  


What are JavaScript Data Types?

1 Answers  


Does javascript have the concept level scope?

1 Answers  


How to use "join()" to create a string from an array using javascript?

1 Answers  


Is it possible to use javascript to change the meta-tags of the page?

1 Answers  


How do you declare javascript?

1 Answers  


What is use of settimeout function in javascript?

1 Answers  


What will be the output of the following statements?

1 Answers  


What is new keyword in javascript?

1 Answers  


Categories