【发布时间】:2015-12-30 00:40:27
【问题描述】:
我的资产文件夹中有一个 xls 文件,我想使用 jexcelapi 库打开它。我已将文件的路径设置为(“file:///android_asset/jxlrwtest.xls”),甚至尝试使用 New-> File 在我的根文件夹中创建一个具有不同名称的 xls 文件并直接访问它但我仍然每次运行模拟器时都会收到错误 java.io.FileNotFoundException "(No such file or directory)"。我还确保每次尝试移动文件时都刷新了路径。我的整个阅读excel文件的课程是
package com.example.kirikedictionary;
import java.io.File;
import java.io.IOException;
import android.app.Activity;
import android.content.Context;
import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class ReadExcel {
private String inputFile;
protected Context context;
public ReadExcel(Context context){
this.context = context.getApplicationContext();
}
public void setInputFile(String inputFile) {
this.inputFile = inputFile;
}
public void read() throws IOException {
File inputWorkbook = new File(inputFile);
Workbook w;
try {
w = Workbook.getWorkbook(inputWorkbook);
// Get the first sheet
Sheet sheet = w.getSheet(0);
// Loop over first 10 column and lines
for (int j = 0; j < sheet.getColumns(); j++) {
for (int i = 0; i < sheet.getRows(); i++) {
Cell cell = sheet.getCell(j, i);
CellType type = cell.getType();
if (type == CellType.LABEL) {
System.out.println("I got a label "
+ cell.getContents());
}
if (type == CellType.NUMBER) {
System.out.println("I got a number "
+ cell.getContents());
}
}
}
} catch (BiffException e) {
e.printStackTrace();
}
}
public void main(String[] args) throws IOException {
ReadExcel test = new ReadExcel(context);
test.setInputFile("file:///android_asset/jxlrwtest.xls");
test.read();
}
}
我不断收到的错误是
12-30 01:36:59.386: W/System.err(1851): java.io.FileNotFoundException: 文件:/android_asset/jxlrwtest.xls:打开失败:ENOENT(没有这样的文件 或目录)12-30 01:36:59.393: W/System.err(1851): at libcore.io.IoBridge.open(IoBridge.java:456) 12-30 01:36:59.393: W / System.err(1851):在 java.io.FileInputStream.(FileInputStream.java:76) 12-30 01:36:59.394:W/System.err(1851):在 jxl.Workbook.getWorkbook(Workbook.java:213) 12-30 01:36:59.394: W/System.err(1851):在 jxl.Workbook.getWorkbook(Workbook.java:198) 12-30 01:36:59.394: W/System.err(1851): 在 com.example.kirikedictionary.ReadExcel.read(ReadExcel.java:33) 12-30 01:36:59.394:W/System.err(1851):在 com.example.kirikedictionary.ReadExcel.main(ReadExcel.java:62) 12-30 01:36:59.394:W/System.err(1851):在 com.example.kirikedictionary.MainActivity$3.onItemClick(MainActivity.java:148) 12-30 01:36:59.394: W/System.err(1851): 在 android.widget.AdapterView.performItemClick(AdapterView.java:300) 12-30 01:36:59.395: W/System.err(1851): 在 android.widget.AbsListView.performItemClick(AbsListView.java:1143) 12-30 01:36:59.416: W/System.err(1851): 在 android.widget.AbsListView$PerformClick.run(AbsListView.java:3044) 12-30 01:36:59.416: W/System.err(1851): 在 android.widget.AbsListView$3.run(AbsListView.java:3833) 12-30 01:36:59.416:W/System.err(1851):在 android.os.Handler.handleCallback(Handler.java:739) 12-30 01:36:59.417:W/System.err(1851):在 android.os.Handler.dispatchMessage(Handler.java:95) 12-30 01:36:59.432:W/System.err(1851):在 android.os.Looper.loop(Looper.java:135) 12-30 01:36:59.432: W / System.err(1851):在 android.app.ActivityThread.main(ActivityThread.java:5221) 12-30 01:36:59.432:W/System.err(1851):在 java.lang.reflect.Method.invoke(本机方法)12-30 01:36:59.432: W / System.err(1851):在 java.lang.reflect.Method.invoke(Method.java:372) 12-30 01:36:59.433: W / System.err(1851):在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 12-30 01:36:59.433: W/System.err(1851): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 12-30 01:36:59.433: W/System.err(1851): 由: android.system.ErrnoException:打开失败:ENOENT(没有这样的文件或 目录)12-30 01:36:59.434:W/System.err(1851):在 libcore.io.Posix.open(本机方法)12-30 01:36:59.435: W / System.err(1851):在 libcore.io.BlockGuardOs.open(BlockGuardOs.java:186) 12-30 01:36:59.451:W/System.err(1851):在 libcore.io.IoBridge.open(IoBridge.java:442) 12-30 01:36:59.452: W/System.err(1851): ... 18 更多
请帮忙,因为我不想使用外部 sd 卡文件,我已经卡在这里一段时间了。
【问题讨论】:
-
请将您的项目导入 Android Studio。 Eclipse 已被弃用,它会产生更多类似的问题
标签: java android eclipse excel android-emulator