java - 编译出现问题: Symbol error in csv file split in java

标签 java arrays csv command-line

我在尝试从命令行运行程序时遇到错误。

我的源代码是:

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

谁能建议我如何修复这个错误?

最佳答案

根据您的代码和错误消息,您收到错误的原因是编译器找不到“In”类和“Out”类。

当您编译程序时,您只是编译“Split.java”文件。为了编译 Split.java 所需的其他类文件,您必须显式告诉编译器也编译这些其他类。如果它们与 Split.java 位于同一文件夹中,那么编译它们所需要做的就是在命令行中运行它:

javac In.java Out.java Split.java

关于java - 编译出现问题: Symbol error in csv file split in java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60048228/

相关文章:

java - JSON服务器生成JSON(java语言)

java - AKKA 消息超时

java - 我如何知道可以存储在数组中的元素的最大范围?

c - 二维数组中 '\0' 的问题

javascript - 使用 JavaScript 遍历数组查找数字的倍数

java - "Implicit wait"等待元素可点击、显示或可见

java - 如何将一批.jpeg文件转换为.gif动画?

c# - 写入 CSV 日志文件

php - 为 SilverStripe 创建自定义 CSV 导入器

python - 从分隔的行创建列表