Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7001495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:48:37+00:00 2026-05-27T20:48:37+00:00

I have a Java project that reads UTF-8 encoded .txt files in order to

  • 0

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.

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 with UTF-8 character encoding using

<compilerarg line="-encoding utf-8"/>

but obviously this is not enough, what do I need to modify to get this to work?

Thanks

Edit 1

I read the .txt files in with.

public String fileToString(String file) {
    InputStream in = new BufferedInputStream(Gdx.files.internal(file).read());
    return new Scanner(in).useDelimiter("\\A").next();
}

which returns a string to a String variable, then I simply take this string and pass it to an object

It works ok when compiling and running within eclipse.

Edit 2

This is the 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 Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:48:38+00:00Added an answer on May 27, 2026 at 8:48 pm

    As per The documentation, use encoding='utf-8' instead of compiler-arg.

    However … I suspect that your problem is runtime, not compile time. Do you create OutputStreamWriter objects without passing an encoding? Or pass interesting chars to System.out.println? Or correspondingly InputStreamReader or Scanner? The fix in this case would be to add -Dfile.encoding=utf-8 to the command line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project in Java I am running that uses an external JAR
I have a Java project in Eclipse with ~10 packages and ~10 class files
I have a Java project that needs a addon interface. I was thinking about
I have a Java project that I'm trying to implement with a model-view-controller design.
I have a Java project that I build using an Ant script. I am
Say I have a GUI Java project of something that simulates an ATM machine,
i have a java ee project which has a text file that uses a
In a software-project written in java you often have resources, that are part of
Java Newbie here. I have a JFrame that I added to my netbeans project,
I have a java project that runs on a webserver. I always hit this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.