

Open the General palette and drag the Function object. In the text file properties, set Mode to Write and type log.txt in the Resource field. Drag the Text file object from the Connectivity palette. If the file does not exist, the model will create a new one.Ĭreate a new model. If it exists, the model will erase its contents. Upon startup, the model will check if there is a file log.txt in the model folder. We will create a function writeToLog( String info ) that will write a string to a specific text file. This solution is an alternative to the default built-in log and may make sense if you wish to always keep the model log in a file. This function is typically used as a while loop condition. The function canReadMore() returns true if there is more information to read, and false if the end of file is reached. Each read or skip operation advances the pointer toward the end of file. Tokens and separators When you are reading a text file, there is always a pointer to the current position in the file. readString() called at the current position will read and return "Airbus A380" and place the pointer to here Current Separator ( ) position Token

The typical separators are listed in the text file properties, and you can provide custom ones. The latter way requires that you specify the token separators in the file so that AnyLogic knows, for example, where the string token ends. You can read the text files byte by byte and line by line, taking care of parsing, or you can use higher level functions like readString(), It is done by using the print(), println(), and printf() functions. The text file object can work in READ, WRITE and WRITE_APPEND modes. The file can be identified by the file name or by the URL. Text file object and properties A particular file can be associated with the text file object at design time by entering its name in the text file properties, or dynamically at runtime by calling setFile() or setURL() functions. The Text file object is located in the Connectivity palette (see the Figure). It takes care of file opening/closing, and provides a higher-level API.

In addition to the (always available) Java i/o API, AnyLogic offers the text file object that simplifies access to text files.

Text files In simulation modeling, text files are used primarily to: © XJ Technologies Simulation Modeling with AnyLogic: Agent Based, Discrete Event and System Dynamics Methods If you export a model as a Java applet and publish it on the web, the security restrictions will prevent the applet from accessing any data (even the clipboard contents) on the end-user machine. The model is virtually never a closed system Please note that communication with the external world is fully available when you either run the models from the AnyLogic development environment, or export them as Java applications. System clipboard, command line parameters, etc. Databases: Oracle, MS SQL Server, MS Access, My SQL, … Each scenario is illustrated with an example. This chapter explains how you can build data exchange interfaces to the external world. In most industrial applications, the model reads and writes to text files, spreadsheets, or databases, or talks directly to other applications via Java. In simple cases, the model has a GUI, where the user enters parameter values in the edit boxes or changes them using sliders, and views the output charts and animation on the screen. It receives various kinds of input data from outside, and outputs the simulation results. Simulation Modeling with AnyLogic: Agent Based, Discrete Event and System Dynamics MethodsĮxchanging data with external world A simulation model is virtually never a closed system.
