--- title: FileReader.readAsText() slug: Web/API/FileReader/readAsText tags: - API - File API - Reference - ファイル - メソッド translation_of: Web/API/FileReader/readAsText --- <div>{{APIRef("File API")}}</div> <p><strong><code>readAsText()</code></strong> メソッドは、指定された {{domxref("Blob")}} または {{domxref("File")}} の内容を読み取るために使用します。読み取り操作が完了すると、 {{domxref("FileReader.readyState","readyState")}} が <code>DONE</code> に変わり、 {{event("loadend")}} イベントが発生し、 {{domxref("FileReader.result","result")}} プロパティにはファイルの内容が文字列として格納されます。</p> <div class="blockIndicator note"> <p><strong>より新しい API が利用できます</strong><br> {{domxref("Blob.text()")}} メソッドは、ファイルをテキストとして読み取るための新しい Promise ベースの API です。</p> </div> <h2 id="Syntax" name="Syntax">構文</h2> <pre class="syntaxbox notranslate"><var>instanceOfFileReader</var>.readAsText(<var>blob</var>[, <var>encoding</var>]);</pre> <h3 id="Parameters" name="Parameters">引数</h3> <dl> <dt><code>blob</code></dt> <dd>メソッドで読み込む {{domxref("Blob")}} または {{domxref("File")}} オブジェクトです。</dd> <dt><code>encoding</code> {{optional_inline}}</dt> <dd>読込の際に使用する文字エンコーディングを指定する文字列です。この引数が指定されなかった場合は UTF-8 で解釈されます。</dd> </dl> <h2 id="Specifications" name="Specifications">仕様</h2> <table class="standard-table"> <thead> <tr> <th scope="col">仕様書</th> <th scope="col">状態</th> <th scope="col">備考</th> </tr> </thead> <tbody> <tr> <td>{{SpecName("File API", "#FileReader-interface", "FileReader")}}</td> <td>{{Spec2("File API")}}</td> <td>初回定義</td> </tr> </tbody> </table> <h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザの互換性</h2> <p>{{Compat("api.FileReader.readAsText")}}</p> <h2 id="See_also" name="See_also">あわせて参照</h2> <ul> <li>{{domxref("FileReader")}}</li> </ul>