I am trying to read a text file using JavaScript and display the content in html file.
Its working as I have created the browse button to select the text file but I want to read the content from a fixed path file. In this program instead of taking the file path I want to read file from the path like - D:/new folder/abc.text
I am using the following code:
<html>
<input type="file" id="fileinput"/>
<script type="text/javascript">
function readSingleFile(evt) {
var f = evt.target.files[0];
if (f) {
var r = new FileReader();
r.onload = function(e) {
var contents = e.target.result;
document.write("the contents of the file are<br>");
document.write(contents);
}
r.readAsText(f);
} else {
alert("Failed to load file");
}
}
document.getElementById('fileinput').addEventListener('change',readSingleFile,false);
</script>
</html>