throw new IOException("Cannot create data file, only names file created.");
throw new IOException("Cannot create data file, only names file created (Reason: " + ex.toString() + ").");
  public void writeBatch() throws IOException {            Instances instances = getInstances();            if(instances == null)          throw new IOException("No instances to save");      if(instances.classIndex() == -1){          instances.setClassIndex(instances.numAttributes()-1);          System.err.println("No class specified. Last attribute is used as class attribute.");      }      if(instances.attribute(instances.classIndex()).isNumeric())          throw new IOException("To save in C4.5 format the class attribute cannot be numeric.");      if(getRetrieval() == INCREMENTAL)          throw new IOException("Batch and incremental saving cannot be mixed.");            setRetrieval(BATCH);      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.");      }      setWriteMode(WRITE);      //print names file      setFileExtension(".names");      PrintWriter outW = new PrintWriter(getWriter());      for (int i = 0; i < instances.attribute(instances.classIndex()).numValues(); i++) {        outW.write(instances.attribute(instances.classIndex()).value(i));        if (i < instances.attribute(instances.classIndex()).numValues()-1) {            outW.write(",");        } else {            outW.write(".\n");	}      }      for (int i = 0; i < instances.numAttributes(); i++) {        if (i != instances.classIndex()) {            outW.write(instances.attribute(i).name()+": ");            if (instances.attribute(i).isNumeric() || instances.attribute(i).isDate()) {                outW.write("continuous.\n");            } else {                Attribute temp = instances.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();            //print data file      String out = retrieveFile().getAbsolutePath();      setFileExtension(".data");      out = out.substring(0, out.lastIndexOf('.')) + getFileExtension();      File namesFile = new File(out);      try{        setFile(namesFile);        setDestination(retrieveFile());      } 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());      // print data file      for (int i = 0; i < instances.numInstances(); i++) {	Instance temp = instances.instance(i);        for(int j = 0; j < temp.numAttributes(); j++){            if(j != instances.classIndex()){                if (temp.isMissing(j)) {		      outW.write("?,");		    } else if (instances.attribute(j).isNominal() || 			       instances.attribute(j).isString()) {		      outW.write(instances.attribute(j).value((int)temp.value(j))+",");		    } else {		      outW.write(""+temp.value(j)+",");		    }            }        }        // write the class value        if (temp.isMissing(instances.classIndex())) {            outW.write("?");        }         else {            outW.write(instances.attribute(instances.classIndex()).value((int)temp.value(instances.classIndex())));        }        outW.write("\n");      }      outW.flush();      outW.close();      setFileExtension(".names");      setWriteMode(WAIT);      outW = null;      resetWriter();      setWriteMode(CANCEL);  }