I have a Java project that reads UTF-8 encoded .txt files to build lines that are displayed. Running in Eclipse files is read and displayed as expected, but after the ant build, the characters do not exit as they should.
Here is my build.xml file
<?xml version="1.0"?> <project name="Rutherford" default="jar"> <property name="libsSrc" value="libs"/> <property name="build" value="build"/> <property name="classes" value="build/classes"/> <property name="jar" value="build/jar"/> <property name="libs" value="build/libs"/> <path id="classpath"> <fileset dir="${libsSrc}" includes="*.jar"/> </path> <pathconvert property="mf.classpath" pathsep=" "> <path refid="classpath"/> <mapper> <chainedmapper> <flattenmapper/> <globmapper from="*.jar" to="lib/*.jar"/> </chainedmapper> </mapper> </pathconvert> <target name="clean" description="remove intermediate files"> <delete dir="build"/> </target> <target name="compile" description="compile the Java source code to class files"> <mkdir dir="${classes}"/> <javac srcdir="." destdir="${classes}" classpathref="classpath"> <compilerarg line="-encoding utf-8"/> </javac> </target> <target name="jar" depends="compile" description="create a Jar file for the application"> <mkdir dir="${jar}"/> <jar destfile="${jar}/App.jar"> <zipgroupfileset dir="${libsSrc}" includes="*.jar"/> <fileset dir="${classes}" includes="**/*.class"/> <manifest> <attribute name="Main-Class" value="nat.rutherford.DesktopStarter"/> <attribute name="Class-Path" value="${mf.classpath}"/> </manifest> </jar> </target> </project>
I tried to compile UTF-8 character encoding using
<compilerarg line="-encoding utf-8"/>
but obviously this is not enough, what do I need to change to get this to work?
thanks
Change 1
I read .txt files with.
public String fileToString(String file) { InputStream in = new BufferedInputStream(Gdx.files.internal(file).read()); return new Scanner(in).useDelimiter("\\A").next(); }
which returns the string to the String variable, I just take that string and pass it to the object
It works fine when compiling and running in eclipse.
Edit 2
This fix
public String fileToString(String file) { InputStream in = new BufferedInputStream(Gdx.files.internal(file).read()); return new Scanner(in, "UTF-8").useDelimiter("\\A").next(); }
Simple when you know where to look! lol Thank you!
source share