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 9236843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:23:45+00:00 2026-06-18T07:23:45+00:00

I have just run into a very strange problem with getResourceAsStream(). In my prod

  • 0

I have just run into a very strange problem with getResourceAsStream().

In my prod project JUnit test I read test data using getResourceAsStream(), I found that getResourceAsStream() sometimes substitutes some bytes:

byte[] fileBytes = FileUtils.readFileToByteArray(new File(
    "resources/test/parser/test-short-enc.xml"));

printBytes(fileBytes);

byte[] classPathBytes = IOUtils.toByteArray(ParserTest.class
    .getResourceAsStream("/test/parser/test-short-enc.xml"))

printBytes(classPathBytes);

In this project output looks like this:

D0 9A D1 80 D0 B8 D0 BC D0 B8 D0 BD D0 B0 D0 BB D0 B8 D1 81 D1 82 D0 B8 D0 BA D0 B0

D0 9A D1 80 D0 B8 D0 BC D0 B8 D0 BD D0 B0 D0 BB D0 B8 D1 3F D1 82 D0 B8 D0 BA D0 B0

After this, I decided to create a small bug-showing project and host it at Github as an example. Here’s the link: https://github.com/snowindy/getResourceAsStream-Bug

I essentially copied the code needed, after run, I could not see the problem reproducing:

D0 9A D1 80 D0 B8 D0 BC D0 B8 D0 BD D0 B0 D0 BB D0 B8 D1 81 D1 82 D0 B8 D0 BA D0 B0

D0 9A D1 80 D0 B8 D0 BC D0 B8 D0 BD D0 B0 D0 BB D0 B8 D1 81 D1 82 D0 B8 D0 BA D0 B0

The printBytes function looks like this:

public static void printBytes(byte[] bv) {
    System.out.println();
    for (byte b : bv) {
        System.out.print(' ');
        System.out.print(String.format("%02X", b));
    }
}

What can it be??

I use eclipse, UTF-8 workspace encoding, the file contains cyrilic word “Криминалистика”, it’s a UTF-8 no-BOM file.

I use JavaSE-1.6 (jdk1.6.0_29) for both projects,
I have Windows 7 OS, windows-1252 system encoding.

UPDATE

I was finally able to reproduce the bug. I updated the project so you can test it: https://github.com/snowindy/getResourceAsStream-Bug

The bug appears only if you have this code in maven pom.xml. This means it’s maven-specific

<build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
        <resource>
            <directory>resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
...
  • 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-06-18T07:23:46+00:00Added an answer on June 18, 2026 at 7:23 am

    Ok, I’ve got the answer.

    This configuration fixes the problem:

    <project>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    ...
    

    I got inspired with this answer: https://stackoverflow.com/a/8979120/792313

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

Sidebar

Related Questions

I just made a very simple website, but I have run into a problem.
I've just installed VS2008 and have run into a problem that I'm sure can
Very new to android and have just done a database tutorial and run into
I have run into a very interesting problem trying to debug my custom PHP
I'm tracking a bug and I run into very strange behaviour. I have set
I have encountered a very strange problem when trying to insert multiple Strings into
I am writing an Android app and have run into a very strange situation.
I have a very strange problem with my code. It will fully run the
i've just run into the infamous tombstoning problem/issue in WP7. let's say i have
I've just started playing around with box2dweb and have now run into a problem

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.