Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
BeanIo can't read special caracters

I have a .txt file with ANSI (windows-1252) Encoding i'am able to read it on windows but not on unix.

here is the xml mapping file :

  <beanio>
    <stream name="empData" format="csv">
        <parser>
            <property name="delimiter" value=";"/>
            <property name="alwaysQuote" value="false"/>
            <!--<property name="quote" value='' />-->
        </parser>    

            <record name="emp" class="com.MyClass" >
            <field name="name" />
            <field name="job" />
            <field name="adress"/>  
       </record>
    </stream>
</beanio>

Java Side :

StreamFactory factory = StreamFactory.newInstance();

    InputStream in = this.getClass().getClassLoader()
            .getResourceAsStream("mapping.xml");

    Reader reader = new InputStreamReader(this.getClass().getClassLoader()
            .getResourceAsStream("countries.txt"));
    factory.load(in);

    BeanReader beanReader = factory.createReader("empData", reader);
    Gson gson = new Gson();
    /*Object bean =new Object();*/
    Object record = null;
    while ((record = beanReader.read()) != null) {
        System.out.println(beanReader.getRecordName() + ": "
                +((MyClass)record).getCountry());
    }

Result : line : France

line : S??o Paulo should be (São Paulo) windows OK but unix is KO

line : USA

line : China

Any idea ?

FYI : i already tried to set Charset to UTF-8 java side .

new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("clearings.txt"), Charset.forName("UTF-8"));
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It's a bit late but... if you have a ANSI file a.k.a. ISO-8859-1, you have to set the InputStreamReader charset as ISO-8859-1, not UTF-8.

Reader reader = new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("clearings.txt"), StandardCharsets.ISO_8859_1);
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda