need help with outputting an array of objects to a text file. new to java so any help would be much appreciated
thanks
johnny

I assume you want to serialize your objects.

FileOutputStream fos = new FileOutputStream("objects.ext");
ObjectOutputStream oos = new ObjectOutputSream(fos);
oos.writeObject(myObject);
oos.close();

You may have to implement Serializable if you want to write your own classes. If the classes of the java library doesnt implement Serializable just make a new class, extended of that class and implement it then without any other changes.
You just have to add

implement Serializable

after your

public class MyClass (extends .... whatever)

The Serializable interface doesnt have any methods you had to implement.

import java.util.*;
class Logic
{
    Scanner in()
    {   return new Scanner(System.in);  }

    void out(String n)
    {   System.out.print(n);    }

    public Logic()
    {
        int n;
        out("Enter N: ");
        n=in().nextInt();
        for(int i=0;i<=n;i++)
        {
            for(int j=0;j<=i;j++)
                out(""+j+ " ");
            out("\n");
        }
    }
    public static void main(String[] args)
    {   new Logic();    }
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

soumitaabasu,

First post of each thread is a question and rest posts are conversation. If you have a problem regarding to programming then create a new thread.

Now, before you post any question please read the rules of this forum:
1. Homework Policy
2. How to post your question?

@sotvisal
Use code tags. Wrap up source code with bb code tags.

For example,

[CODE=Java] ..... .... here is your program source code.

[/code]

This article has been dead for over six months. Start a new discussion instead.