How can you read a file line by line in JavaScript?

前端 未结 4 486
眼角桃花
眼角桃花 2020-12-03 15:38

I\'m writing a web-app for the iPad that will be loading data from a text file. (A sample data set is around ~400 kb). I have everything set up except the file reading. The

4条回答
  •  不思量自难忘°
    2020-12-03 16:15

    Mobile Safari doesn't have the File API, so I assume you're talking about reading from a web resource. You can't do that. When you read a resource via ajax, the browser will first read it fully into memory and then pass the entire string to your ajax callback as a string.

    In your callback, you can take the string and break it into lines, and wrap that up in an object that has the API that your code wants, but you're still going to have the string in memory all at once..

提交回复
热议问题