java를 사용하여 Excel 파일을 읽으려고합니다. 프로그램 컴파일 중에 잘못된 문자로 오류가 발생합니다. 이 문제를 해결하도록 도와주세요. 프로그램이 사람이이 문제를 해결하는 데 도움이 수Java에서 잘못된 문자 오류가 발생했습니다.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\vino>cd C:\Program Files\jdk1.6.0_10\bin
C:\Program Files\jdk1.6.0_10\bin>javac Readingexcel.java
Readingexcel.java:1: illegal character: \187
import java.io.IOException;
^
Readingexcel.java:1: illegal character: \191
import java.io.IOException;
^
2 errors
같은 오류가 발생하고 컴파일하는 동안 여기에 코드를
import java.io.IOException;
import java.io.*;
import java.util.Iterator;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFRow;
public class Readingexcel {
public static void main(String[] args) {
try {
System.out.println("before reading");
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("input.xlsx"));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheet("first");
HSSFRow row;
HSSFCell cell;
String s;
int rows; // No of rows
rows = sheet.getPhysicalNumberOfRows();
System.out.println(rows);
System.out.println(sheet.getRow(1).getPhysicalNumberOfCells());
int cols = 0; // No of columns
int tmp = 0;
// This trick ensures that we get the data properly even if it doesn’t start from first few rows
for (int i = 0; i < 10 || i < rows; i++) {
row = sheet.getRow(i);
if (row != null) {
tmp = sheet.getRow(i).getPhysicalNumberOfCells();
if (tmp > cols) {
cols = tmp;
}
}
}
for (int r = 0; r < rows; r++) {
row = sheet.getRow(r);
if (row != null) {
for (int c = 0; c < cols; c++) {
cell = row.getCell((short) c);
if (cell != null) {
// Your code here
// s = cell.getData();
System.out.println(cell.getStringCellValue());
}
}
}
}
} catch (Exception ioe) {
ioe.printStackTrace();
}
}
}
입니다.
파일의 시작 부분에 보이지 않는 문자가 있습니다. 문제를 해결할 수 없다면 소스를 새 파일로 복사하고 이전 파일을 삭제하십시오. – kba
당신은 input.xlsx를 게시 할 수 있습니다 – L7ColWinters
소스에'∩╗┐'이있는 것 같습니다 ... .java 파일을 메모장에서 열면 어떻게됩니까? – beny23