Save+Instances+to+an+ARFF+File

toc = Converter = You should use the class  for saving a  object to a file.

Here is the snippet : code format="java" Instances dataSet = ... ArffSaver saver = new ArffSaver; saver.setInstances(dataSet); saver.setFile(new File("./data/test.arff")); saver.setDestination(new File("./data/test.arff"));  // **not** necessary in 3.5.4 and later saver.writeBatch; code
 * Notes:**
 * using the converter approach, one can easily swap the with another saver, e.g., the  to output the data in a different format.
 * The Weka Examples collection dedicates quite a few examples to the use of converters in the package:
 * [|book]
 * [|stable-3.6]
 * [|developer]

= Java I/O = You can also save the object directly using Java I/O classes: code format="java" import java.io.BufferedWriter; import java.io.FileWriter; ... Instances dataSet = ... BufferedWriter writer = new BufferedWriter(new FileWriter("./data/test.arff")); writer.write(dataSet.toString); writer.flush; writer.close; code
 * Note:** using the of the  doesn't scale very well for large datasets, since the complete string has to fit into memory. It is best to use a converter, as described in the previous section, which uses an incremental approach for writing the dataset to disk.