Developing Apama Applications > Developing Adapters > Standard Apama Adapters > Apama File adapter > Opening comma separated values (CSV) files
Opening comma separated values (CSV) files
An example of defining an OpenFileForReading event that opens a CSV file so that each field is automatically parsed appears below. The additional data required by the CSV codec is stored in the payload dictionary.
com.apama.file.OpenFileForReading openCSVFileRead :=
new com.apama.file.OpenFileForReading;
 
//matches transport in IAF config
openCSVFileRead.transportName := JMultiFileTransport;
 
//the request id to use
openCSVFileRead.requestId := integer.getUnique();
 
//read using JCSVCodec
openCSVFileRead.codec := "JCSVCodec";
 
//file to read
openCSVFileRead.filename := "/usr/home/formby/stocktick.csv";
 
//separator char is a ","
openCSVFileRead.payload["separator"] := ",";
 
//emit event to channel in config.
emit openCSVFileRead to "FILE";
Subsequently, when the File adapter receives FileLine events, the adapter stores each field in the data sequence in order. You can access the ones you are interested in.
For details about using the CSV codec, see The CSV codec plug-in.
Copyright © 2013 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.