APS Excellence in Physics Education Award
November 2019

Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

Data Output post and replies

Return to the Data Output thread
Login to post to this thread

Data Output
Tom Dooling
2 Posts

How can I write out data from a simulation to another file? It used to be I could copy and paste from a data table, but that does not seem to be possible now. Do I need custom java code to create and write to a file?

Replies to Data Output

Re: Data Output -
Francisco Esquembre
228 Posts


There are reading model elements, particularly for text files. To WRITE a file, you have to use plain Java.

Attached is an example of such a possible code that opens a text file and writes data to it as it gets generated. Don't forget to close the file before quitting the simulation. Study the code and you will quickly see how it works and be able to adapt it to your needs.


PS: We have done nothing to the data table that prevents it from copying and pasting. Please send me  (fem@um.es) the example and I will have a close look at it.

Post edited June 25, 2012 at 12:07 PM EST.

Attached File: ejs_WritingToTextFile.zip

Re: Re: Data Output -
Tom Dooling
2 Posts

Hi Paco,


Your code was very easy to incorporate into my own simulation.
It works and I'm writing out my data files with no issues.

Thanks again for such a quick response!

Tom Dooling

Re: Re: Re: Data Output -
Francisco Esquembre
228 Posts

You are welcome.

Around the world in a few seconds! :-)


OSP Projects:
Open Source Physics - EJS Modeling
Physlet Physics
Physlet Quantum Physics
STP Book