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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:35:57+00:00 2026-05-27T17:35:57+00:00

I need to load a text file which is placed in res/raw directory into

  • 0

I need to load a text file which is placed in res/raw directory into memory. Here is my code:

package com.ggd543.android;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TextView;

import java.io.IOException;
import java.io.InputStream;

public class FileActivity extends Activity {
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        loadText();
    }

    private void loadText() {
//        InputStream is = Resources.getSystem().openRawResource(R.raw.text);
        InputStream is = getResources().openRawResource(R.raw.text);
        try {
            byte[] buf = new byte[is.available()];
            is.read(buf, 0, buf.length);
            ((TextView) findViewById(R.layout.main)).setText(new String(buf, "UTF-8"));
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
}

}

When I deploy the .apk on emulator and start it up, I got the following error:

12-25 14:33:38.096: ERROR/AndroidRuntime(3077): Uncaught handler: thread main exiting due to uncaught exception
12-25 14:33:38.106: ERROR/AndroidRuntime(3077): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ggd543.android/com.ggd543.android.FileActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030000
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
        at android.app.ActivityThread.access$2200(ActivityThread.java:119)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:4363)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:521)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030000
        at android.content.res.Resources.getValue(Resources.java:891)
        at android.content.res.Resources.openRawResource(Resources.java:816)
        at android.content.res.Resources.openRawResource(Resources.java:798)
        at com.ggd543.android.FileActivity.loadText(FileActivity.java:23)
        at com.ggd543.android.FileActivity.onCreate(FileActivity.java:19)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
        ... 11 more

Could anyone give me suggestion ?

Thx

  • 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-27T17:35:58+00:00Added an answer on May 27, 2026 at 5:35 pm

    Move the file to the assets folder.

    Then retrieve the stream like this InputStream is = getAssets().open("fileName");

    if you have assets/mytxtfile.txt
    then fileName = “mytxtfile.txt”

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

Sidebar

Related Questions

I need to load a file from an umounted TrueCrypt disk into memory. Is
I have entries in a text file which I want to load into a
I need to load from text file text which I will be replacing in
I need to be able to load the entire contents of a text file
I need to load a .xml file from a URL adress into an NSData
Two Delphi programs need to load foo.dll, which contains some code that injects a
I need to load database content into a JTable . Many times I search
I have a large text file I need to sort in Java. The format
Im trying to load a csv file into a datatable using oledb. This is
Suppose I have a 400K text file which I want to read from a

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.