954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Array output

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

jpd85
Newbie Poster
1 post since Jun 2004
Reputation Points: 11
Solved Threads: 0
 

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.

Pogo
Newbie Poster
4 posts since Jul 2004
Reputation Points: 11
Solved Threads: 0
 

I want to know the logic for the output
0
0 1
0 1 2
0 1 2 3
0 1 2 3 4

soumitaabasu
Newbie Poster
1 post since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

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(); }
}

sotvisal
Newbie Poster
21 posts since Jul 2009
Reputation Points: 6
Solved Threads: 0
 

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]

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You