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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:48:20+00:00 2026-06-02T15:48:20+00:00

well basically I want to do this, class myclass { int a1; float b1;

  • 0

well basically I want to do this,

class myclass
{
    int a1;
    float b1;
    char c1;     //This is a single character
}
List<myclass> obs;

now at run-time this obs variable as it is a list will contain array of the myclass instances
whose size we get obs.size();

So, how to write this data to file say “data1.bin” as binary using OutputStream or some thing similar. But this is to be done in Android OS.

I did something like this in c++ like

class myclass
{
    int a1;
    float b1;
    char c1;
}

myclass student1;

ofstream output_file("students.data", ios::binary);
output_file.write((char*)&student1, sizeof(student1));
output_file.close()

But How to do this in Android OS?

  • 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-02T15:48:21+00:00Added an answer on June 2, 2026 at 3:48 pm

    if you want to dump your class to file, let the class implement Serializable and java (or Dalvik VM on android) will do this for you behind the scene.

    class MyClass implements Serializable {
    
        private static final long serialVersionUID = 1L;
    
        int a1;
        float b1;
        char c1;     //This is a single character
    }
    
    
    private File file;
    private MyClass myClass;
    
    private void writeIt() throws IOException {
    
        ObjectOutputStream stream = null;
        try {
            stream = new ObjectOutputStream(new FileOutputStream(file));
            stream.writeObject(myClass);
        } 
        finally {
            if(stream != null) {
                stream.close();
            }
        }
    }
    
    private MyClass readIt() throws IOException, ClassNotFoundException {
    
        ObjectInputStream stream = null;
        try {
            stream = new ObjectInputStream(new FileInputStream(file));
            return (MyClass) stream.readObject();
        } 
        finally {
            if(stream != null) {
                stream.close();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I basically want to the C of equivalent of this (well, just the part
Basically, I want to do the reverse of this question . I'm getting XML
I have a class which I want to expose a list of structs (which
At the moment all I want this program to do is run without any
Well, I have a class Customer (no base class). I need to cast from
Well, how to create picture link like this up or down votes (on the
Well, I am storing variables inside of a class that will be used for
Someone please help me return this list properly from my view. I don't see
I have code that basically looks like this (it isn't actually object, but rather
I have some code below. This code is a basic push/pop stack class that

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.