Compare Revisions

Reading textual data

Change Revisions

Revision 96918:

Revision 96918 by Dria on

Revision 96919:

Revision 96919 by Jumpin on

Title:
Reading textual data
Reading textual data
Slug:
Reading_textual_data
Reading_textual_data
Tags:
Extensions, Add-ons, Internationalization, Unicode
Extensions, Add-ons, Internationalization, Unicode
Content:

Revision 96918
Revision 96919
t175    </p>t175      // First, get and initialize the converter var converter = 
 >Components.classes{{mediawiki.external('\"@mozilla.org/intl/scrip
 >tableunicodeconverter\"')}}
176    <h3 name="See_also">
177      See also
178    </h3>
179    <p>176    </p>
180      <a href="en/Writing_textual_data">Writing textual data</a>177    <pre class="eval">
181    </p>{{ wiki.languages( { "ja": "ja/Reading_textual_data" } ) 178                         .createInstance(Components.interfaces.ns
>}}>IScriptableUnicodeConverter);
179</pre>
180    <p>
181      converter.charset = /* The character encoding you want, usi
 >ng UTF-8 here */ "UTF-8";
182    </p>
183    <p>
184      // This assumes that 'file' is a variable that contains the
 > file you want to read, as an nsIFile var fis = Components.classe
 >s{{mediawiki.external('\"@mozilla.org/network/file-input-stream;1
 >\"')}}
185    </p>
186    <pre class="eval">
187                   .createInstance(Components.interfaces.nsIFileI
 >nputStream);
188</pre>
189    <p>
190      fis.init(file, -1, -1, 0);
191    </p>
192    <p>
193      var lis = fis.QueryInterface(Components.interfaces.nsILineI
 >nputStream); var lineData = {}; var cont; do {
194    </p>
195    <pre class="eval">
196 cont = lis.readLine(lineData);
197 var line = converter.ConvertToUnicode(lineData.value);
198</pre>
199    <pre class="eval">
200 // Now you can do something with line
201</pre>
202    <p>
203      } while (cont); fis.close();
204    </p>

Back to History