Reading text files with FileReader

<script>function readfile(f) {
    var reader = new FileReader();  
    reader.readAsText(f);          
    reader.onload = function() {    
        var text = reader.result;
        var out = document.getElementById('output');  
        out.innerHTML = '';                            
        out.appendChild(document.createTextNode(text)); 
    }
    reader.onerror = function(e) {  
        console.log('Error', e);
    };
}
</script>
Select the file to display:
<input type='file' onchange='readfile(this.files[0])'></input>
<pre id='output'></pre>