1. 程式人生 > >FileReader讀取檔案

FileReader讀取檔案

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>H5 file</title>
</head>
<body>
<script>
    function readfile(f){
        var reader = new FileReader();
        reader.readAsText(f,'GB2312');//讀取檔案
        reader.onload = function(){
            var
text = reader.result; text = text.replace(/[\s+,'[&#26825;&#33457;&#31958;&#23567;&#35828;&#32593;&#77;&#105;&#97;&#110;&#104;&#117;&#97;&#116;&#97;&#110;&#103;&#46;&#99;&#99;']/g, ""); text = text.replace(/['。']/g
, "\n"); text = text.replace(/站頁面清爽\W{24}/g, ""); text = text.replace(/更新快\W{24}/g, ""); 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 id="h5file" type="file" onchange = "readfile(this.files[0])"> <pre id="output"></pre><!-- 程式碼輸出 --> </body> </html>