How to store the content of arrays in a file

I worked out a java program for indexing purpose in an information retrieval system. I defined three arrays: file, IndexTerm[j] and TF[j], where file is name of the file numbered by i, IndexTerm[j] to is the single term numbered by j, and TF[j] is the number of times the IndexTerm[j] is mentioned in the text of file. What I need to do now is to store the content of these arrays in a file. Could anyone show me how to do that? Thanks.

[478 byte] By [Wenxiaoa] at [2007-10-2 9:12:39]
# 1
http://java.sun.com/docs/books/tutorial/essential/io/
CeciNEstPasUnProgrammeura at 2007-7-16 23:19:41 > top of Java-index,Java Essentials,Java Programming...
# 2

There's lots of possible aproaches. It depends on stuff like how the file is to be retrived, are there rules as to the way the file is structured. Are non-java applications like to read the file?

The simplest way, programatically, is probable to use serialization and simply pass the arrays to an ObjectOutputStream. You have to make sure that all the objects involved implement Serializable and follow the simple rules for serializable objects (most library objects comply).

malcolmmca at 2007-7-16 23:19:41 > top of Java-index,Java Essentials,Java Programming...
# 3

for writing :-

int[ ] i = new int[5];

for(int j=0;j<=4j++)

i[j] = j;

try

{

FileOutputStream fos = new FileOutputStream(FILENAME);

ObjectOutputStream oos = new ObjectOutputStream(fos);

}

catch(Exception e);

oos.writeObject(i);

oos.close();

-

for reading : -

try

{

FileInputStream fis = new FileInputStream(FILENAME);

ObjectInputStream ois = new ObjectInputStream(fis);

}catch(Exception e)

int i[] = new int[5];

i = (int [ ] ) ois.readObject( );

barjeshjavaa at 2007-7-16 23:19:41 > top of Java-index,Java Essentials,Java Programming...