简体   繁体   中英

How to add instances from text file to an arff file by using java

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();

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM