ViggieSmalls
ViggieSmalls

Reputation: 73

no source has been specified Weka using eclipse on windows

I'm trying to convert a csv file to arff using some Java code I found, but I keep getting the IO error that no source has been specified.

How should I make the file path because a standard "C:\user\user1\Desktop\folder\file.csv" one isn't working for me?

Here is the code I am using:

import weka.core.Instances;
import weka.core.converters.ArffSaver;
import weka.core.converters.CSVLoader;
import java.io.File;

public class CSV2Arff {

  public static void main(String[] args) throws Exception {

    // load CSV
    CSVLoader loader = new CSVLoader();
    loader.setSource(new File("file path"));
    Instances data = loader.getDataSet();//get instances object

    // save ARFF
    ArffSaver saver = new ArffSaver();
    saver.setInstances(data);//set the dataset we want to convert
    //and save as ARFF
    saver.setFile(new File("file path"));
    saver.writeBatch();
  }
} 

Upvotes: 0

Views: 2452

Answers (1)

Johny
Johny

Reputation: 2188

Your file path should be specified like this

loader.setSource(new File("C:\\Users\\user1\\Desktop\\file1\\file.csv"));

You should use \\ instead of \.

Upvotes: 2

Related Questions