Exception in thread "main" java.io.IOException: No source has been specified

122 Views Asked by At

I'm using Java to create a program that takes in a CSV file and outputs an Arff file. Whenever the program runs it comes up catching the exception that No source has been specified. When I delete the try catch it comes with the following error and I am not sure why,

Exception in thread "main" java.io.IOException: No source has been specified 
at weka.core.converters.CSVLoader.getDataSet(CSVLoader.java:867) 
at CSVtoArff.Convert(CSVtoArff.java:10) 
at CSVtoArff.main(CSVtoArff.java:23)

Below is the code for the program

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

public class CSVtoArff {
    public static void Convert(String input, String output) throws Exception {
        try {
            CSVLoader load = new CSVLoader();
            load.setSource(new File(input));
            Instances data = load.getDataSet();
            
            
            ArffSaver save = new ArffSaver();
            save.setInstances(data);
            save.setFile(new File(output));
            save.writeBatch();
            System.out.println("File successfully converted");
        }
        catch (Exception e) {
            System.out.println("Does not meet arff standards: " + e.getMessage());
        }
        
        
            
    }
    public static void main(String[] args) throws Exception{
        String input = "C:\\Users\\jason\\Desktop\\example.csv";
        String output =" C:\\Users\\jason\\Desktop\\example.arff";
        
        Convert(input, output);
    }
}
1

There are 1 best solutions below

0
Gyanendra Dwivedi On

Please try putting the files in C:\temp folder and change it to below and try. Sometime windows security my be denying access to protected system folders. Also there is an extra leading space in output file path. I have removed that.

 public static void main(String[] args) throws Exception{
        String input = "C:/temp/example.csv";
        String output ="C:/temp/example.arff";
        
        Convert(input, output);
    }