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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:07:31+00:00 2026-05-15T10:07:31+00:00

Is it possible to write objects in Java to a binary file? The objects

  • 0

Is it possible to write objects in Java to a binary file? The objects I want to write would be 2 arrays of String objects. The reason I want to do this is to save persistent data. If there is some easier way to do this let me know.

  • 1 1 Answer
  • 1 View
  • 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-15T10:07:31+00:00Added an answer on May 15, 2026 at 10:07 am

    If you want to write arrays of String, you may be better off with a text file. The advantage of using a text file is that it can be easily viewed, edited and is usuable by many other tools in your system which mean you don’t have to have to write these tools yourself.

    You can also find that a simple text format will be faster and more compact than using XML or JSON. Note: Those formats are more useful for complex data structures.

    public static void writeArray(PrintStream ps, String... strings) {
        for (String string : strings) {
            assert !string.contains("\n") && string.length()>0;
            ps.println(strings);
        }
        ps.println();
    }
    
    public static String[] readArray(BufferedReader br) throws IOException {
        List<String> strings = new ArrayList<String>();
        String string;
        while((string = br.readLine()) != null) {
            if (string.length() == 0)
                break;
            strings.add(string);
        }
        return strings.toArray(new String[strings.size()]);
    }
    

    If your start with

    String[][] theData = { { "a0 r0", "a0 r1", "a0 r2" } {"r1 c1"} }; 
    

    This could result in

    a0 r0
    a0 r1
    a0 r2
    
    r1 c1
    

    As you can see this is easy to edit/view.

    This makes some assumptions about what a string can contain (see the asset). If these assumptions are not valid, there are way of working around this.

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

Sidebar

Related Questions

Is it possible to write this query in codeigniter active records? $Main_Nav_Query = mysql_query(SELECT
This is very similar to another question ( Functional Data Structures in Java )
Would it be possible to write Eclipse plugin, that: Whenever in our code we
I want to write the equivalent Java code of a C# code. My C#
I am considering a design in Java where I want a string object but
I have several objects that look like this: class PhoneNumber { String getNumber(); String
Is it possible to write a method in Scala which returns an object of
Is possible to write language agnostic Robotium tests? For example, if you use a
Is it possible to write GLSL ES fragment shaders under iOS that generate multiple
Is it possible to write generic class with one constructor which explicitly defines type

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.