Sample code in angularjs, to read and write text file -
i new this.the solutions getting internet reading file , displaying is, want read file line line.
var lines = this.result.split('\n'); for(var line = 0; line < lines.length; line++){ console.log(lines[line]); }
with \n
can split file @ linebreaks.
question vague solution when want output file line line.
context:
first need input file, can achieve via html:
<input type="file" name="file" id="filename">
now create js function grab file:
document.getelementbyid('filename').onchange = function(){ // declare file variable var filevar = this.files[0]; //the reader: var datareader = new filereader(); reader.onload = function(progressevent){ };
i included filereader, can see
can combine full function:
document.getelementbyid('filename').onchange = function(){ var filevar = this.files[0]; var datareader = new filereader(); reader.onload = function(progressevent){ var lines = this.result.split('\n'); for(var line = 0; line < lines.length; line++){ console.log(lines[line]); } }; datareader.readastext(filevar); };
this bit tutorialish sry, guess helps more code.
Comments
Post a Comment