Pergunta

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();
Foi útil?

Solução

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();
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top