I am new in javascript and was trying to read and write in local txt file so I did as I found in the web but for some reason it stucks in new File instantiation:
<script type="text/javascript">
var txtFile = "d:/test.txt"
alert('point 1');
var file = new File(txtFile);
alert('point 2');
</script>
It prints only 'point 1' string. Thanks.
new File()
constructor requires at least two parameters; first parameter an array containingString
,ArrayBufferView
,ArrayBuffer
Blob
or anotherFile
object; the second the file name. You cannot specify a download directory for files usingjavascript
, but you can set a download directory at browser settings or preferences. You can also utilizedownload
attribute ata
element to set file name atSave File
dialog.You could use
<input type="file">
element to retrievetest.txt
, and edit.txt
file at<textarea>
before re-saving with same file name. See also Edit, save, self-modifying HTML document; format generated HTML, JavaScript , How to Write in file (user directory) using JavaScript?