Java – 在控制台使用参数启动程序时出错

huangapple go评论79阅读模式
英文:

Java - Error starting program with arguments in console

问题

以下是您要求的翻译内容:

一般情况下,不涉及水。输入是以CSV格式表示的链接(文件路径),每行(数组)应输出。为了方便起见,我下载了一个第三方库来处理CSV文件。通过命令行运行。编译顺利,做了一切正确的事情(某种程度上),注册了库的路径等:

E:\projects\java.Adam2.0\src\com\company>javac -cp "E:\projects\Librari\opencsv-5.2.jar" QI100.java

E:\projects\java.Adam2.0\src\com\company>cd E:\projects\java.Adam2.0\src

我运行了(就像...我不太确定了),正确地指定了参数(文件路径),但是它给出了以下错误:

E:\projects\java.Adam2.0\src>java QI100 C:\Users\ARTHUR\Downloads\file.csv

错误:

错误:找不到或加载主类 QI100
原因:java.lang.ClassNotFoundException: QI100

忘记了代码本身:

package com.company;

import com.opencsv.CSVReader;
import com.opencsv.exceptions.CsvValidationException;

import java.io.*;
import java.util.ArrayList;
import java.util.List;


public class QI100 {
    public void main (String[] args) throws IOException, FileNotFoundException, CsvValidationException {
        String pathToFile = args[0];
        BufferedReader reader = new BufferedReader(new FileReader(pathToFile));
        CSVReader csvReader = new CSVReader(reader);
        ArrayList<String[]> lineArray = new ArrayList<>();
        String[] line;
        while ((line = csvReader.readNext()) != null) {
            lineArray.add(line);
            System.out.println(line);
        }
    }
 }

如果您有任何其他需要翻译的内容,请随时提问。

英文:

In general, no water. The input is a link (path to the file) in CSV format, each line (array) should be output. For convenience, I downloaded a third-party library to work with CSV files. Running through the command line. Compiles well, did everything right (sort of), registered the path to the library, etc .:

E:\projects\java.Adam2.0\src\com\company>javac -cp "E:\projects\Librari\opencsv-5.2.jar" QI100.java

E:\projects\java.Adam2.0\src\com\company>cd E:\projects\java.Adam2.0\src

I run (like ... I'm not sure here anymore) correctly, specifying the argument (path to the file), but it gives the following error:

E:\projects\java.Adam2.0\src>java QI100 C:\Users\ARTHUR\Downloads\file.csv

ERROR:

Error: Could not find or load main class QI100
Caused by: java.lang.ClassNotFoundException: QI100

Forgot about the code itself:

package com.company;

import com.opencsv.CSVReader;
import com.opencsv.exceptions.CsvValidationException;

import java.io.*;
import java.util.ArrayList;
import java.util.List;


public class QI100 {
    public void main (String[] args) throws IOException, FileNotFoundException, CsvValidationException {
        String pathToFile = args[0];
        BufferedReader reader = new BufferedReader(new FileReader(pathToFile));
        CSVReader csvReader = new CSVReader(reader);
        ArrayList<String[]> lineArray = new ArrayList<>();
        String[] line;
        while ((line = csvReader.readNext()) != null) {
            lineArray.add(line);
            System.out.println(line);
        }
    }
 }

答案1

得分: 0

你已经在E:\projects\java.Adam2.0\src\com\company处编译了Java文件,而你正试图在E:\projects\java.Adam2.0\src处访问它。因此,系统无法找到这个类。请使用以下命令:

E:\projects\java.Adam2.0\src>javac -d . -cp "E:\projects\Librari\opencsv-5.2.jar" QI100.java

E:\projects\java.Adam2.0\src>java -cp "E:\projects\Librari\opencsv-5.2.jar" com.company.QI100 C:\Users\ARTHUR\Downloads\file.csv

注意: . 指定了当前目录,而开关 -d 指定了生成的类文件存放的位置。要了解更多信息,只需使用命令 javac

英文:

You have compiled the Java file at E:\projects\java.Adam2.0\src\com\company while you are trying to access it at E:\projects\java.Adam2.0\src. Therefore, the system is not able to find the class. Use the command as follows:

E:\projects\java.Adam2.0\src>javac -d . -cp "E:\projects\Librari\opencsv-5.2.jar" QI100.java

E:\projects\java.Adam2.0\src>java -cp "E:\projects\Librari\opencsv-5.2.jar" com.company.QI100 C:\Users\ARTHUR\Downloads\file.csv

Note: The . specifies the current directory and the switch -d specifies where to place generated class files. To learn more about it, just use the command, javac.

huangapple
  • 本文由 发表于 2020年7月26日 02:24:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/63091985.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定