编译中的数组问题:java中csv文件拆分中的符号错误
试图从命令行运行程序时出错
我的源代码是:
public class Split {
public static void main(String[] args) {
String name = args[0]; // base file name
int n = Integer.parseInt(args[1]); // number of fields
String delimiter = args[2]; // delimiter (comma)
// create one output stream for each of the N fields
Out[] out = new Out[n];
for (int i = 0; i < n; i++) {
out[i] = new Out(name + i);
}
// read in the input and divide by field
In in = new In(name + ".csv");
while (in.hasNextLine()) {
String line = in.readLine();
String[] fields = line.split(delimiter);
for (int i = 0; i < n; i++) {
out[i].println(fields[i]);
}
}
}
}
我得到的错误是:
C:\Users\zunayeed\Desktop\jav>javac Split.java Split.java:8: error: cannot find symbol Out[] out = new Out[n]; ^ symbol: class Out location: class Split Split.java:8: error: cannot find symbol Out[] out = new Out[n]; ^ symbol: class Out location: class Split Split.java:10: error: cannot find symbol out[i] = new Out(name + i); ^ symbol: class Out location: class Split Split.java:14: error: cannot find symbol In in = new In(name + ".csv"); ^ symbol: class In location: class Split Split.java:14: error: cannot find symbol In in = new In(name + ".csv"); ^ symbol: class In location: class Split 5 errors
有人能建议我如何修正这个错误吗
# 1 楼答案
根据您的代码和错误消息,出现错误的原因是编译器找不到“In”类和“Out”类
在编译程序时,您只是在编译“拆分”。java的文件。以编译拆分的其他类文件。java要求,您必须显式地告诉编译器编译其他类。如果它们与拆分位于同一文件夹中。java,那么编译它们所要做的就是在命令行中运行: