How to read a local text file?

前端 未结 20 2262
北恋
北恋 2020-11-21 05:28

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.

20条回答
  •  被撕碎了的回忆
    2020-11-21 06:07

    Jon Perryman,

    Yes js can read local files (see FileReader()) but not automatically: the user has to pass the file or a list of files to the script with an html .

    Then with js it is possible to process (example view) the file or the list of files, some of their properties and the file or files content.

    What js cannot do for security reasons is to access automatically (without the user input) to the filesystem of his computer.

    To allow js to acccess to the local fs automatically is needed to create not an html file with js inside it but an hta document.

    An hta file can contain js or vbs inside it.

    But the hta executable will work on windows systems only.

    This is standard browser behavior.

    Also google chrome worked at the fs api, more infos here: http://www.html5rocks.com/en/tutorials/file/filesystem/

提交回复
热议问题