Skip to content

Instantly share code, notes, and snippets.

@gaishimo
Created July 23, 2013 03:52
Show Gist options
  • Save gaishimo/6059730 to your computer and use it in GitHub Desktop.
Save gaishimo/6059730 to your computer and use it in GitHub Desktop.
HTML5 FILE APIのテキストファイル読み込みサンプル
var onFileSelect = function(ev){
var file = ev.target.files[0];
var reader = new FileReader();
reader.readAsText(file, 'UTF-8');
reader.onload = function(ev){
var i, l;
var txt = ev.target.result;
var lines = txt.split(/\r\n/);
for( i = 0, l= lines.length; i < l; i++ ){
console.log(lines[i]);
}
};
};
document.getElementById('files')
.addEventListener('change', onFileSelect, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment