I’m trying to write a simple text file reader by creating a function that takes in the file’s path and converts each line of text into a char array, but it’s not working.
In order to read a local file text through JavaScript
using chrome, the chrome browser should run with the argument --allow-file-access-from-files
to allow JavaScript to access local file, then you can read it using XmlHttpRequest
like the following:
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
var allText = xmlhttp.responseText;
}
};
xmlhttp.open("GET", file, false);
xmlhttp.send(null);