title: Java application reads UTF-8 encoded text files but after ant build the characters are not as expected
body: <p>I have a Java project that reads UTF-8 encoded .txt files in order to construct strings that are displayed. Running in Eclipse the files are read and displayed as expected but after my ant build the characters are not coming out as they should.</p>
  
  <p>Here is my build.xml file</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;project name="Rutherford" default="jar"&gt;
  
      &lt;property name="libsSrc" value="libs"/&gt;
      &lt;property name="build" value="build"/&gt;
      &lt;property name="classes" value="build/classes"/&gt;
      &lt;property name="jar" value="build/jar"/&gt;
      &lt;property name="libs" value="build/libs"/&gt;
  
      &lt;path id="classpath"&gt;
              &lt;fileset dir="${libsSrc}" includes="*.jar"/&gt;
      &lt;/path&gt;
  
      &lt;pathconvert property="mf.classpath" pathsep=" "&gt;
              &lt;path refid="classpath"/&gt;
              &lt;mapper&gt;
                      &lt;chainedmapper&gt;
                              &lt;flattenmapper/&gt;
                              &lt;globmapper from="*.jar" to="lib/*.jar"/&gt;
                      &lt;/chainedmapper&gt;
              &lt;/mapper&gt;
      &lt;/pathconvert&gt;
  
      &lt;target name="clean" description="remove intermediate files"&gt;
          &lt;delete dir="build"/&gt;
      &lt;/target&gt;
  
      &lt;target name="compile" description="compile the Java source code to class files"&gt;
          &lt;mkdir dir="${classes}"/&gt;
          &lt;javac srcdir="." destdir="${classes}" classpathref="classpath"&gt;
              &lt;compilerarg line="-encoding utf-8"/&gt;
          &lt;/javac&gt;
      &lt;/target&gt;
  
      &lt;target name="jar" depends="compile" description="create a Jar file for the application"&gt;
          &lt;mkdir dir="${jar}"/&gt;
          &lt;jar destfile="${jar}/App.jar"&gt;
              &lt;zipgroupfileset dir="${libsSrc}" includes="*.jar"/&gt;
              &lt;fileset dir="${classes}" includes="**/*.class"/&gt;
              &lt;manifest&gt;
                  &lt;attribute name="Main-Class" value="nat.rutherford.DesktopStarter"/&gt;
                  &lt;attribute name="Class-Path" value="${mf.classpath}"/&gt;
              &lt;/manifest&gt;
          &lt;/jar&gt;
      &lt;/target&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>I tried to compile with UTF-8 character encoding using</p>
  
  <pre><code>&lt;compilerarg line="-encoding utf-8"/&gt;
  </code></pre>
  
  <p>but obviously this is not enough, what do I need to modify to get this to work?</p>
  
  <p>Thanks</p>
  
  <p><strong>Edit 1</strong></p>
  
  <p>I read the .txt files in with.</p>
  
  <pre><code>public String fileToString(String file) {
      InputStream in = new BufferedInputStream(Gdx.files.internal(file).read());
      return new Scanner(in).useDelimiter("\\A").next();
  }
  </code></pre>
  
  <p>which returns a string to a String variable, then I simply take this string and pass it to an <a href="http://libgdx.l33tlabs.org/docs/api/com/badlogic/gdx/scenes/scene2d/ui/Label.html" rel="nofollow">object</a></p>
  
  <p>It works ok when compiling and running within eclipse.</p>
  
  <p><strong>Edit 2</strong></p>
  
  <p>This is the fix</p>
  
  <pre><code>public String fileToString(String file) {
      InputStream in = new BufferedInputStream(Gdx.files.internal(file).read());
      return new Scanner(in, "UTF-8").useDelimiter("\\A").next();
  }
  </code></pre>
  
  <p>Simple when you know where to look! lol Thanks!</p>