我的文件读取API代码一直运行得很好,直到有一天我从一个客户那里得到了一个280MB的txt文件。在Chrome中页面直接崩溃,在Firefox中什么也没有发生。
// create new reader object
var fileReader = new FileReader();
// read the file as text
fileReader.readAsText( $files[i] );
fileReader.onload = function(e)
{ // read all the information about the file
// do sanity checks here etc...
$timeout( function()
{
// var fileContent = e.target.result;
// get the first line
var firstLine = e.target.result.slice(0, e.target.result.indexOf("\n") ); }}
我试图在上面做的是获取第一个换行符,以便我可以获取文件的列长度。我不应该把它读成文本吗?在大型文件中如何获取文件的列长度而不破坏页面?