Priya
Priya

Reputation: 1

csv to arff conversion

I am a beginner of java i want to convert the existing .csv file into .arff file and i have written the below code and its not converting instead i am getting the errors. please can anybody help me in solving these errors and suggest me how program :

import weka.core.Instances;
import weka.core.converters.ArffSaver;
import weka.core.converters.CSVLoader;

import java.io.File;
import java.io.IOException;

public class meena {
  /**
   * takes 2 arguments:
   * - CSV input file
   * - ARFF output file
   */
  public static void main(String[] args) throws IOException {

      String args0="C:\\Documents and Settings\\CORI\\My Documents\\NetBeansProjects\\trainingset\\build\\classes\\svmlearn\\in.csv ";
      String args1="C:\\Documents and Settings\\CORI\\My Documents\\NetBeansProjects\\trainingset\\build\\classes\\svmlearn\\output1.txt";
    // load CSV
    CSVLoader loader = new CSVLoader();
    loader.setSource(new File(args0));
    Instances data = loader.getDataSet();

    // save ARFF
    ArffSaver saver = new ArffSaver();
    saver.setInstances(data);
    saver.setFile(new File(args[1]));
    saver.setDestination(new File(args[1]));
    saver.writeBatch();
  }
}



I am getting the below error:
---Registering Weka Editors---
Trying to add database driver (JDBC): RmiJdbc.RJDriver - Error, not in CLASSPATH?
Trying to add database driver (JDBC): jdbc.idbDriver - Error, not in CLASSPATH?
Trying to add database driver (JDBC): com.mckoi.JDBCDriver - Error, not in CLASSPATH?
Trying to add database driver (JDBC): org.hsqldb.jdbcDriver - Error, not in CLASSPATH?
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
    at meena.main(meena.java:26)
Java Result: 1

Please help me to convert .csv file into .arff file by suggesting me clearly how and where to pass the input

Upvotes: 0

Views: 2078

Answers (1)

Walter
Walter

Reputation: 2811

There are two points here.

  1. On line 26 you use args[1] when I believe you mean to use args1.
  2. Trying to add database driver (JDBC) does not prevent your code from running successfully.

Upvotes: 1

Related Questions