Read a local file using javascript

How do I get the contents of a local file, say:


in a variable x in javascript?

Can I use the filereader http://www.w3.org/TR/file-upload/#dfn-filereader? If yes, then how?


You can't do this with strict javascript, but you can use the web server as an intermediate between the user and the browser. Have the user upload the file asynchronously (using AJAX). The web server could then return the plain-text value back to the AJAX call. The contents would then be free to use as you see fit.

This is likely your only option without employing Flash/Silverlight/Java.


Reading client files in javascript is possible indeed with the new File API available in modern browsers (I dont know if IE supports this now). Check this site and its code: <strong>http://www.readfileonline.com/</strong> it allows you to read files using the browser only.


  • Numerically solving an equation
  • Retrieving variables from .txt error; Batch
  • interpolation in 3d computer graphics
  • Does Angular assign itself to `window.angular` globally, when loaded as CommonJS module?
  • Do stored procedures have the ability to delete a file from the OS?
  • Start another EXE in Managed Code
  • white-space: pre-wrap not working in IE
  • toString() for each element of an array in Javascript [duplicate]
  • How to properly add strings to QListWidgets?
  • Must EOT be at the bebinning in the line?
  • Generate list with conditional items
  • How can I selectively modify the src attributes of script tags in an HTML document using Perl?
  • Webpack-dev-server and isomorphic react-node application
  • Reading from Windows registry in Perl [duplicate]
  • File loader changed image file name but not the file name in HTML file
  • Feature detection of foreignObject in SVG
  • Why does the font in these TD elements render at different sizes?
  • XSD with multi occurrences unordered
  • Get the pasted content on document on paste event
  • garbled css name when styling within UiBinder
  • How to open html table in xls on click of a button
  • In loopback documentation what does variable 'cb' stands for?
  • joining two bezier curves
  • what makes a request a new request in asp.net C#
  • nodemcu custom firmware build problems
  • perl, mysql - fasting way to upload a csv file into mysql?
  • Redirect STDERR in OPEN pipe comand. Perl Linux
  • System.InvalidCastException: Specified cast is not valid
  • Jetty 9 HashLoginService
  • azure media services - The request body is too large and exceeds the maximum permissible limit
  • MongoError: Incorrect arguments
  • ImageMagick, replace semi-transparent white with opaque white
  • Cannot connect to cassandra from Spark
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • Cross-Platform Protobuf Serialization
  • Alternatives to the OPTIONAL fallback SPARQL pattern?
  • Do I've to free mysql result after storing it?
  • Unanticipated behavior
  • coudnt use logback because of log4j
  • Turn off referential integrity in Derby? is it possible?