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

  • Home
  • SEARCH
  • 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 6382967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:35:28+00:00 2026-05-25T02:35:28+00:00

I have a jar compiled with core jdk. It contains a java class which

  • 0

I have a jar compiled with core jdk.

It contains a java class which reads a txt file.
It has a test which proves that this class works correctly.

If I include this jar in my android project and then call the java class that reads the txt file. It fails reporting: java.io.FileNotFoundException and adding a ‘/’ to the path of the txt file which I wanted to load.

Is Android’s security model stopping the txt file from being read?

My Project structure:

Android Module:

src/Loader.java [calls GetName.java]

Java Module:

test/TestGetName.java [calls GetName.java]

src/GetName.java

resources/names.txt

Summary:

TestGetName.java works

Loader.java fails. A FileNotFoundException is thrown inside GetName

  • 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-25T02:35:29+00:00Added an answer on May 25, 2026 at 2:35 am

    Figured it out in the end. I need a condition to see if I am loading the file locally or as a resource. There is probably a neater way to do this without using a conditional.

        String source = "resources/inputfile.txt";
        BufferedReader fin;
    
        InputStream inputStream = getClass().getResourceAsStream(source.substring(source.lastIndexOf("/")));
        if (inputStream != null) {
            fin = new BufferedReader(new InputStreamReader(inputStream));
        } else {
            fin = new BufferedReader(new FileReader(new File(source)));
        }
    

    Thanks for the hints about reading as a resource user77777777

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

Sidebar

Related Questions

I have a jar file I produced from compiled class files using an ant
I have a 3rd party JAR file that is compiled using Java 1.4. Is
I have a java compiled library in a jar.for which i have written documentation
I have a jar file that has a file named client.ts in (when viewing
I have a jar file that uses some txt files. In order to get
I have a jar on the classpath which contains a hibernate.properties. This causes problems
That is when you have any jar file attached to you your class path.
I have one jar dependency in my java project that contains sources as well
I have a .jar file that i've placed in my D:\Coldfusion8\wwwroot\web-inf\lib\ directory. The file
I have a JAR file named helloworld.jar . In order to run it, I'm

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.