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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:20:08+00:00 2026-06-03T01:20:08+00:00

I m using read & write string to internal memory. My WriteFavData is working

  • 0

I m using read & write string to internal memory. My “WriteFavData” is working fine. But In “ReadFavData” is not working. Actually when i reach the line if(favFile.exists()) in ReadFavData(..,..), it says file not found & execute the else part. I have already check the emulator internal memory using command line shell access adb shell cat /data/data/com.android.mypackage/files/fav_data_channel, the file is there. Why is saying file is not present.? Any ideas….

    public boolean ReadFavData(Context context, String channelName)
        {
            boolean isFileFound = false;
            FileInputStream fin ;
            StringBuffer strContent = new StringBuffer("");
            String fileName = FAV_FILE_NAME + "_" + channelName;
            File favFile = new File(fileName);
            int ch;
            if(favFile.exists())
            {
                isFileFound = true;
                try {
                    fin = context.openFileInput(FAV_FILE_NAME + "_" + channelName);
                    isFileFound = true;
                    while ((ch = fin.read()) != -1)
                        {
    strContent.append((char) ch);
    }

                    fin.close();                


                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }       
            }
            else 
            {
                Log.i(TAG, "not found");
            }

            return isFileFound;
        }



public boolean WriteFavData(Context context, String channelName)
        {
            String favStr;
            FileOutputStream fos ;
            JSONObject videos = new JSONObject();           
            videos.put("videos", favJsonArray);
            String favStr = videos.toJSONString(); //note.toString();
            String fileName = FAV_FILE_NAME + "_" + channelName;
            File f = new File(fileName);
            if(f.exists())
            {
                Log.i("Old FIle", "Found");
                f.delete();     
            }

            if(f.exists())
                Log.i("Still", "Exist");

            try {               
                    fos = context.openFileOutput(FAV_FILE_NAME + "_" + channelName, Context.MODE_PRIVATE);              
                fos.write(favStr.getBytes());
                fos.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }       
            return true;
        }

Actually, i debugged again & track that on line if(file.exists()), the file is not present.. But if i comment this line & read my file directly, i m able to read file successfully. Whats wrong with if(file.exists())?

  • 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-03T01:20:09+00:00Added an answer on June 3, 2026 at 1:20 am

    favFile.exists() always returns false here, because it will not go to your private data directory to check it. openFileInput or openFileOutput will do.

    Remove it and catch a FileNotFoundException for openFileInput.

    Or you can add path to your private data directory before favFile name.

    new File("/data/data/com.android.mypackage/files/fav_data_channel").exists();
    

    will be true then.

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

Sidebar

Related Questions

I am read & write username & password to android device using my application
I am using MySql DB and want to be able to read & write
Currently, I'm using ReadFile() and WriteFile() APIs to write & read from file. are
I'm using read/write locks on Linux and I've found that trying to upgrade a
I'm reading from the standard input using the read() system call but there's a
I have a string with possible command line arguments (using an Read-Eval-Print-Loop program) and
I am not able to open a url for read() using urllib or urllib2
This code: void Controller::write(const std::string& str) { std::cout << Writing: [ << str <<
I am implementing a buffer of fixed length to read or write a string
When i write using StreamWriter.WriteLine, it adds CRLF to the string and sends it

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.