swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating output files in java


From: Isis GIRALDO
Subject: Re: Creating output files in java
Date: Tue, 31 Jul 2001 16:31:42 +0200

Hi again,
thanks a lot for your answer but I  have a question for you related to
your way of solving this. Where should I create the instance of
FileOutpout class? For each agent I need to save a value and besides I
need to  do it for every simulation step. At the end of the simulations
I should have an enormous file with 3 values for all the agents at every
simulation step. I have tried your solution but don't understand where
to create the new instance, where to write the line (to get what I want)
and where to close the file. This class FileWriter doesn't have the
option of opening an existing file, well at least I haven't dound it.

Many many thanks indeed for your help,
Isis


Olivier Jauze wrote:

> 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.

                  ==================================
   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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]