Articles → JAVASCRIPT → Read Text File In Javascript Using Filereader

Read Text File In Javascript Using Filereader

Text file

Picture showing the sample text file

Click to Enlarge

Read text file

  1. Add a file upload control
  2. Add a reference of jQuery
  3. Add file upload change event
  4. Use FileReader object to read text file.

<!DOCTYPE html>
<html lang="en" xmlns="">
      <meta charset="utf-8" />
      <script src="jquery-3.1.1.js"></script>
         $(document).ready(function () {
             $("#upload").change(function (evt) {                
                 for (var i = 0, f; f =[i]; i++) {
                     var reader = new FileReader();
                     reader.onload = function (evt) {
         <input type="file" id="upload" />


Picture showing the output of reading the text file in JavaScript using FileReader

Click to Enlarge

Posted By  -  Karan Gupta
Posted On  -  Sunday, February 5, 2017


Your Email Id  
Query/FeedbackCharacters remaining 250