Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From the code you posted, you're not trying to "copy" the stream, but read it into a string.</p> <p>You can simply provide the encoding in <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#String%28byte%5B%5D,%20int,%20int,%20java.lang.String%29" rel="nofollow">the <code>String</code> constructor</a>:</p> <pre><code>s = new String(bytes, "ISO-88591-1"); </code></pre> <p>Personally I'd just replace the whole method with a call to the <a href="https://code.google.com/p/guava-libraries/" rel="nofollow">Guava</a> <a href="http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/com/google/common/io/Files.html#toString%28java.io.File,%20java.nio.charset.Charset%29" rel="nofollow">method <code>Files.toString()</code></a>:</p> <pre><code>String content = Files.toString(new File(filename), StandardCharsets.ISO_8859_1); </code></pre> <p>If you're using Java 6 or earlier, you'll need to use the Guava field <a href="http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/com/google/common/base/Charsets.html#ISO_8859_1" rel="nofollow">Charsets.ISO_8859_1</a> instead of <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/charset/StandardCharsets.html#ISO_8859_1" rel="nofollow"><code>StandardCharsets.ISO_8859_1</code></a> (which was only introduced in Java 7).</p> <p><em>However</em> your use of the term "copy" suggests that you want to write the result to some other file (or stream). <em>If that is true</em>, then you don't need to care about the encoding at all, since you can just handle the <code>byte[]</code> directly and avoid the (unnecessary) conversion to and from <code>String</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload