저는 java가 처음입니다. 나는 뛰어난 코드와 함께 작동하는 코드를 작성 중이다. 그 목적을 위해 jExcel API를 사용하고 있습니다.jExcel에서 작업 할 때 파일을 찾을 수없는 예외가 발생했습니다.
이제 내 코드는 다음과 같습니다.
import java.io.File;
import jxl.*;
class main{
private File outputFile;
private String destinationFolder;
public main(){
this.destinationFolder="test";
}
public void fileIteration(){
try{
for(File fileEntry : new File(this.destinationFolder).listFiles()){
if (fileEntry.isDirectory()){
}
else{
System.out.println(fileEntry.getName());
this.excelManipulate(fileEntry.getName());
}
}
}
catch(Exception e){
e.printStackTrace();
}
}
public void excelManipulate(String inputFile){
try{
System.out.println(inputFile);
Workbook workbook=Workbook.getWorkbook(new File("test/"+inputFile));
Sheet sheet=workbook.getSheet(0);
Cell a5=sheet.getCell("a1");
System.out.println(a5.getContents());;
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
public static void main(String[] args){
main ofh=new main();
ofh.fileIteration();
}
}
D : \ java \ Automation \ src \ test에 약간의 엑셀이 있습니다.
이제 Windows의 명령 프롬프트를 사용하여 코드를 컴파일하고 실행합니다.
내가 제공하고있는 컴파일 명령은
javac의의 -cp은 "D : \ 자바 \ 자동화가 \ jexcelapi는 \ jxl.jar"main.java 다음 내가 주요 명령 자바를 실행하고 코드가 제대로 컴파일하는 동안 , 실행 중에 다음 오류가 발생합니다.
D:\java\Automation\src>java main
as307d.xls
as307d.xls
Exception in thread "main" java.lang.NoClassDefFoundError: jxl/Workbook
at main.excelManipulate(main.java:37)
at main.fileIteration(main.java:23)
at main.main(main.java:50)
Caused by: java.lang.ClassNotFoundException: jxl.Workbook
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
jar 파일을 명시 적으로 실행하면 다음과 같은 오류가 발생합니다.
D:\java\Automation\src>java -jar D:\java\automation\jexcelapi\jxl.jar main
java.io.FileNotFoundException: main (The system cannot find the file specified)
java.io.FileNotFoundException: main (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at jxl.Workbook.getWorkbook(Workbook.java:213)
at jxl.Workbook.getWorkbook(Workbook.java:198)
at jxl.demo.Demo.main(Demo.java:276)
나는 왜 파일 이름을 atleast로 인쇄하지 못하고 있는지 잘 모르겠습니다. 제가 실수 한 부분과 코드에 문제가있는 부분을 알려주십시오. 고마워요.
감사 Reimeus하고 문제를 해결 한 JEMS .... 고마워요 :) – Roy