static String[][] parseCSV(String fileName) throws FileNotFoundException, IOException {
int fields;
int lines;
try (BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\hp\\Documents\\Documents\\ID3ALGORITHM\\playtennis.txt"))) {
String s = br.readLine();
fields = 1;
int index = 0;
while ((index = s.indexOf(',', index) + 1) > 0)
fields++;
lines = 1;
while (br.readLine() != null)
lines++;
}
String[][] data = new String[lines][fields];
Scanner sc = new Scanner(new File("C:\\Users\\hp\\Documents\\Documents\\ID3ALGORITHM\\playtennis2.txt"));
sc.useDelimiter("[,\n]");
for (int l = 0; l < lines; l++)
for (int f = 0; f < fields; f++)
if (sc.hasNext())
data[l][f] = sc.next();
else
error("Scan error in " + "playtennis2.txt" + " at " + l + ":" + f);
sc.close();
return data;
} // parseCSV()
public static void main(String[] args) throws FileNotFoundException,IOException {
if (args.length != 2)
error("Expected 2 arguments: file names of training and test data");
String[][] trainingData = parseCSV(args[0]);
String[][] testData = parseCSV(args[1]);
ID3ALGO classifier = new ID3ALGO();
classifier.train(trainingData);
classifier.printTree();
classifier.classify(testData);
} // main()
收到的错误:预期2个参数:训练和测试数据的文件名。为什么会发生什么? parseCSV的参数由同一文件夹中的两个不同文件组成,系统无法读取该文件。