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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:21:59+00:00 2026-05-18T08:21:59+00:00

I did some reading on the API for File IO and read the following

  • 0

I did some reading on the API for File IO and read the following blog post: http://techknock.blogspot.com/2008/05/file-hadling-in-android.html. His code works fine when everything is in the same activity. But what I am trying to do is create an IOInterface class that I can use to open multiple databases to populate multiple lists.

ListA.java

public class ListA
{
    public List<ClassA> list;
    private final String DBA = "dbA";
    private IOInterface database;

    public List()
    {
        list = new ArrayList<ClassA>();
        database = new IOInterface();
    }

    ...

    public void initListA() throws IOException
    {
        database.openForWriting(DBA);

        String myStr = new String("content");
        database.dos.writeBytes(myStr);
        database.dos.flush();
        database.dos.close();
    }
}

IOInterface.java

public class IOInterface
{
    public DataOutputStream dos;
    private FileOutputStream fos;

    public void openForWriting(String database)
    {
        try {
            fos = openFileOutput(database, Content.MODE_PRIVATE);
            dos = new DataOutputStream(fos);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}

Eclipse underlines fos = openFileOutput(database, Content.MODE_PRIVATE);. With the comment that openFileOutput() does not exist. The resolution to this is to extend the IOInteface class as an Activity. I suppose then openFileOutput() is a method of an activity class.

So my question is how do accomplish what I am trying to do? Standard Java file io such as:

File fp = new File("database");
FileOutputStream fos = new FileOutputStream(fp);

does not work. It catches a FileNotFoundException. This has to be doable though. Any ideas?

Thanks,

  • 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-18T08:22:00+00:00Added an answer on May 18, 2026 at 8:22 am

    Method openFileOutput() is contained in the Context class, so you can pass an instance of this class to your method that opens files. And you should always use methods from Context when you want to work with files.

    You can read about using the internal and external storages in the development guide.

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

Sidebar

Related Questions

Say you get a file handle from some outside DLL and instantiate a FileStream
Currently I am making some decisions for my first objective-c API. Nothing big, just
I've got some heavily modified code that ultimately came from the Windows Media SDK
I thought I wanted to use GSS-API, but now am not so sure, since
I suppose this question is more general than working with COM components. I have
Alright, so I'm building a web app that provides music information (i.e. info on
I'm using a ProgressEvent in Flash to determine how long something will take to
Microsoft indicates that VB6 doesn't support ExitProcess (to exit and return a value). However,
Duplicate What are your hard rules about commenting? A Developer I work with had
I am working on a project that allows for video streaming or video-on-demand. I've

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.