[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Creating output files in java
From: |
Olivier Jauze |
Subject: |
Re: Creating output files in java |
Date: |
Fri, 27 Jul 2001 16:39:39 +0200 |
At 16:25 27/07/01 +0200, you wrote:
hi there,
I'm usig swarm with java and need to create an output file with data
from the agents. Initially I tryed to use the EZGraph to create the
sequence but it only allows to write a value on the file by time step. I
need my file to have some information of every agent for every step in
the simulation.
what can I do?
Many thanks and sorry for the ingorance,
Isis
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.
Hi,
I have had exaclty the same issue and this is my solution (someone must
have a better solution but If it can help you ):
I created this class :
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
public class FileOutput
{
protected FileWriter fW;
public FileOutput( String nameFile)
{
try
{
fW = new FileWriter(nameFile);
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
}
protected void writeLine( String lineIn )
{
try
{
fW.write(lineIn + "\n");
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
}
protected void close()
{
try
{
fW.close();
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
}
}
then when I have to write a line in a file I do this:
I declare an instance of this class :
FileOutput fileWorld = new FileOutput("helloWorld.txt");
and I use the java class String to convert data in a string
int year = 2001;
fileWorld .writeLine("Hello world, it is the year " + String.valueOf(year));
Don't forget to close the file, if you do not the file will not contain
anything.
fileWorld .close();
Now you just have to write line at every time step and you obtain the
effect you want.
Here, it is my way to write in a file. I don't think it is the most simple
solution but it works.
Have a good day.
Olivier JAUZE
INRA unité URH équipe SP
Centre de Theix
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.