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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:50:30+00:00 2026-05-26T17:50:30+00:00

I have come across an issue that is driving me nuts xD … (Firstly:

  • 0

I have come across an issue that is driving me nuts xD … (Firstly: Hello everyone! For some reason I cant prepend the “Hello everyone” at the beginning of the post in edits oO…)

The use-case is as follows: I have an xml file stored in my project’s raw folder. The xml file look something like this:

<myxml ....>Some text<innerelement ... /></myxml>

I know there is a folder called xml but what I need is a string – not an XmlResourceParser (which you get when calling context.getResources().getXml(id)).

Now, what I do to load this raw xml file is:

context.getResources().openRawResource(R.raw.myfile)

This returns me an InputStream, which I then try to convert to a String using the following code:

try {
   byte[] buffer = new byte[stream.available()];
   stream.read(buffer);
   stream.close();
   return new String(buffer);
} catch (IOException e) {
   // Error handling
}

If I now print the resulting String to logcat, all I get is a bunch of squares, spread across a few lines.

So I guess I must be missing something there … I tried a few ways of converting this input stream to String already and all of them ended up with the same result (see image above) …

Thanks in advance & best regards,

zainodis

UPDATE 12.11.2011

I tried saving the xml file in the raw folder using the extension .txt instead of .xml. Now the conversion fails with an OutOfMemory exception oO. I tried different way to convert the data using suggestions from this thread – all resulting in a OutOfMemoryException:

11-12 06:09:22.671: I/TestRunner(652): java.lang.OutOfMemoryError
11-12 06:09:22.671: I/TestRunner(652):  at java.util.Scanner.expandBuffer(Scanner.java:2183)
11-12 06:09:22.671: I/TestRunner(652):  at java.util.Scanner.readMore(Scanner.java:2143)
11-12 06:09:22.671: I/TestRunner(652):  at java.util.Scanner.findPostDelimiter(Scanner.java:2121)
11-12 06:09:22.671: I/TestRunner(652):  at java.util.Scanner.setTokenRegion(Scanner.java:2031)
11-12 06:09:22.671: I/TestRunner(652):  at java.util.Scanner.next(Scanner.java:1017)
11-12 06:09:22.671: I/TestRunner(652):  at java.util.Scanner.next(Scanner.java:993)
11-12 06:09:22.671: I/TestRunner(652):  at de.softcon.mobileapp.framework.core.configuration.utility.StringUtils.InputStreamToString(StringUtils.java:69)
11-12 06:09:22.671: I/TestRunner(652):  at de.softcon.mobileoffences.domainmodel.serialization.test.CorpusDelictiFactoryTest.testSerialization(CorpusDelictiFactoryTest.java:32)
11-12 06:09:22.671: I/TestRunner(652):  at java.lang.reflect.Method.invokeNative(Native Method)
11-12 06:09:22.671: I/TestRunner(652):  at java.lang.reflect.Method.invoke(Method.java:507)
11-12 06:09:22.671: I/TestRunner(652):  at junit.framework.TestCase.runTest(TestCase.java:154)
11-12 06:09:22.671: I/TestRunner(652):  at junit.framework.TestCase.runBare(TestCase.java:127)
11-12 06:09:22.671: I/TestRunner(652):  at junit.framework.TestResult$1.protect(TestResult.java:106)
11-12 06:09:22.671: I/TestRunner(652):  at junit.framework.TestResult.runProtected(TestResult.java:124)
11-12 06:09:22.671: I/TestRunner(652):  at junit.framework.TestResult.run(TestResult.java:109)
11-12 06:09:22.671: I/TestRunner(652):  at junit.framework.TestCase.run(TestCase.java:118)
11-12 06:09:22.671: I/TestRunner(652):  at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
11-12 06:09:22.671: I/TestRunner(652):  at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
11-12 06:09:22.671: I/TestRunner(652):  at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529)
11-12 06:09:22.671: I/TestRunner(652):  at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)
  • 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-26T17:50:31+00:00Added an answer on May 26, 2026 at 5:50 pm

    I put this code in onCreate(...). It can show the string in the xml file.

    InputStream stream = getResources().openRawResource(R.raw.data);
    try {
            byte[] buffer = new byte[stream.available()];
            stream.read(buffer);
            stream.close();
            Log.i("xml", new String(buffer));
    } catch (IOException e) {
        // Error handling
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sometimes I have come across this issue that whenever I change the order of
Recently I have come across a curious pattern in some code. We know that
I have come across a large issue that i am having that has suddenly
Please help me with an issue that I have come across during work. I'm
I am designing a contact management system and have come across an interesting issue
Has anyone come across this issue? Seems MS have broken it with their own
I've come across this issue in my application, and have reproduced it using Apple's
I have come across a lot of optimization tips which say that you should
I have come across a Silverlight project that needed to make use of a
I am somewhat new to transactional databases and have come across an issue I

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.