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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:02:36+00:00 2026-06-02T07:02:36+00:00

I have this function and when I call it, it won’t return anything. public

  • 0

I have this function and when I call it, it won’t return anything.

public String getfileFromSDCard(String filename){//get the file
    String text;
    text = "";

    File root = new File(Environment.getExternalStorageDirectory(), "Notes");
    if (!root.exists()) {
        root.mkdirs();
    }
    File file = new File(root,"file.txt");
    try {
        BufferedReader br = new BufferedReader(new FileReader(file));
        String str;

        while ((str = br.readLine()) != null) {
            text = text + str;
        }
        br.close();
    }
    catch (IOException e) {
        e.printStackTrace();
    }
    Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
    return text;
}

Do I need to add any permission to my android manifiest other than

…uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE” … ( I worte this line right in the code)

I have this one added already and running cause I can easily write a file, but I cant read it afterward

This is how I’m calling the function from the onCreate

    TextView countDisplay = new TextView(this);
    CreatefiletoSDCard("testnumberone.txt","22222fkdf sdjf hjsdf sdj fsdf ");
    countDisplay.setText(getfileFromSDCard("testnumberone.txt"));

    this.setContentView(countDisplay);

ps: CreatefiletoSDCard() works.

  • 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-02T07:02:38+00:00Added an answer on June 2, 2026 at 7:02 am

    Although you pass in a filename parameter in your getfileFromSDCard() method, you seem to have hardcoded the actual file(name) you’re reading from to file.txt. Guessing by the filenames you use for creating your test files, the error is probably that you’re trying to read from a non-existent file, no matter what name you actually pass into the method.

    In other words, you probably want to change the following line:

    File file = new File(root,"file.txt");
    

    to:

    File file = new File(root,filename);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this static callback function in MyClass, and I try to call another
I have encounters this abap snippet that I have difficulty to comprehend. call function
I have a UDF in sql server. I want to call this function at
I have a problem when call applet method from javascript.. I used this function
I have identified this call as a bottleneck in a high pressure function. graphics.DrawImage(smallBitmap,
I have DLL and application that will call some function in this dll. For
I have a jQuery AJAX call with type:'GET' like this: $.ajax({type:'GET',url:'/createUser',data:userId=12345&userName=test, success:function(data){ alert('successful'); }
I have this function: public bool IsValidProduct(int productTypeId) { bool isValid = false; if
I have this very annoying issue, whenever i call a function: void renderGame::renderMovingBlock(movingBlock* blockToRender){
I have a VB.NET function which looks like this: <WebMethod()> _ Public Shared Function

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.