Question

I have instances in text file, then I want to add them to an existed arff file. My arff file has relation and couple of attributes, how can I add those instances into specific lines in arff file?

Here is my answer:

BufferedReader reader = new BufferedReader(new FileReader("instances.txt"));
String line = reader.readLine();
FileWriter fw = new FileWriter("testinstances.arff",true);
fw.write(line);
fw.close();
Was it helpful?

Solution

readLine() reads a single line from the reader, modifying your solution to iterate through each line should do what you are attempting:

BufferedReader reader = new BufferedReader(new FileReader("instances.txt"));
String toWrite = "";
String line = null;
while ((line = reader.readLine()) != null) {
    toWrite += line;
}
FileWriter fw = new FileWriter("testinstances.arff",true);
fw.write(toWrite);
fw.close();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top