setDestination(namesFile);
    public void writeIncremental(Instance inst) throws IOException{        int writeMode = getWriteMode();      Instances structure = getInstances();      PrintWriter outW = null;            if(structure != null){          if(structure.classIndex() == -1){            structure.setClassIndex(structure.numAttributes()-1);            System.err.println("No class specified. Last attribute is used as class attribute.");          }          if(structure.attribute(structure.classIndex()).isNumeric())            throw new IOException("To save in C4.5 format the class attribute cannot be numeric.");      }      if(getRetrieval() == BATCH || getRetrieval() == NONE)          throw new IOException("Batch and incremental saving cannot be mixed.");      if(retrieveFile() == null || getWriter() == null){          throw new IOException("C4.5 format requires two files. Therefore no output to standard out can be generated.\nPlease specifiy output files using the -o option.");      }                  outW = new PrintWriter(getWriter());                if(writeMode == WAIT){        if(structure == null){            setWriteMode(CANCEL);            if(inst != null)                System.err.println("Structure(Header Information) has to be set in advance");        }        else            setWriteMode(STRUCTURE_READY);        writeMode = getWriteMode();      }      if(writeMode == CANCEL){          if(outW != null)              outW.close();          cancel();      }      if(writeMode == STRUCTURE_READY){          setWriteMode(WRITE);          //write header: here names file          for (int i = 0; i < structure.attribute(structure.classIndex()).numValues(); i++) {            outW.write(structure.attribute(structure.classIndex()).value(i));            if (i < structure.attribute(structure.classIndex()).numValues()-1) {                outW.write(",");            } else {                outW.write(".\n");            }          }          for (int i = 0; i < structure.numAttributes(); i++) {            if (i != structure.classIndex()) {                outW.write(structure.attribute(i).name()+": ");                if (structure.attribute(i).isNumeric() || structure.attribute(i).isDate()) {                    outW.write("continuous.\n");                } else {                    Attribute temp = structure.attribute(i);                    for (int j = 0; j < temp.numValues(); j++) {                        outW.write(temp.value(j));                        if (j < temp.numValues()-1) {                            outW.write(",");                        } else {                            outW.write(".\n");                        }                    }                }            }          }          outW.flush();          outW.close();                    writeMode = getWriteMode();                    String out = retrieveFile().getAbsolutePath();          setFileExtension(".data");          out = out.substring(0, out.lastIndexOf('.')) + getFileExtension();          File namesFile = new File(out);          try{            setFile(namesFile);            setDestination(namesFile);          } catch(Exception ex){            throw new IOException("Cannot create data file, only names file created.");          }          if(retrieveFile() == null || getWriter() == null){            throw new IOException("Cannot create data file, only names file created.");          }          outW = new PrintWriter(getWriter());      }      if(writeMode == WRITE){          if(structure == null)              throw new IOException("No instances information available.");          if(inst != null){            //write instance: here data file            for(int j = 0; j < inst.numAttributes(); j++){                if(j != structure.classIndex()){                    if (inst.isMissing(j)) {                        outW.write("?,");                    } else                         if (structure.attribute(j).isNominal() ||                             structure.attribute(j).isString()) {                                outW.write(structure.attribute(j).value((int)inst.value(j))+",");                        } else {                                outW.write(""+inst.value(j)+",");                        }                    }            }            // write the class value            if (inst.isMissing(structure.classIndex())) {                outW.write("?");            }             else {                outW.write(structure.attribute(structure.classIndex()).value((int)inst.value(structure.classIndex())));            }            outW.write("\n");            //flushes every 100 instances            m_incrementalCounter++;            if(m_incrementalCounter > 100){                m_incrementalCounter = 0;                outW.flush();            }          }          else{          //close              if(outW != null){                outW.flush();                outW.close();              }              setFileExtension(".names");              m_incrementalCounter = 0;              resetStructure();              outW = null;              resetWriter();          }      }  }