我有一个位于主项目目录中的csv文件调用v1.csv。当我尝试读取燃料时,java似乎永远都找不到它。我使用opencsv和扫描仪解决方案,以便将文件读入2d数组,但这两种方法都不起作用。我该如何让java知道在哪里找到该文件?
扫描仪解决方案:
BufferedReader reader = new BufferedReader(new FileReader(
"v1.csv"));
Opencsv解决方案:
CSVReader reader = new CSVReader(new FileReader("v1.csv"));
Opencsv Alternate:
CSVReader reader = new CSVReader(new FileReader("/Users/yilun/Desktop/v1.csv"));
堆栈追踪:
01-31 10:08:35.671: W/System.err(16946): java.io.FileNotFoundException: /Users/yilun/Downloads/mapquest-android-sdk/samples: open failed: ENOENT (No such file or directory)
01-31 10:08:35.671: W/System.err(16946): at libcore.io.IoBridge.open(IoBridge.java:409)
01-31 10:08:35.671: W/System.err(16946): at java.io.FileInputStream.<init>(FileInputStream.java:78)
01-31 10:08:35.671: W/System.err(16946): at java.io.FileInputStream.<init>(FileInputStream.java:105)
01-31 10:08:35.671: W/System.err(16946): at java.io.FileReader.<init>(FileReader.java:66)
01-31 10:08:35.671: W/System.err(16946): at com.mapquest.android.samples.MyLocationMap.onCreate(MyLocationMap.java:73)
01-31 10:08:35.681: W/System.err(16946): at android.app.Activity.performCreate(Activity.java:6084)
01-31 10:08:35.681: W/System.err(16946): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-31 10:08:35.681: W/System.err(16946): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2181)
01-31 10:08:35.681: W/System.err(16946): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2283)
01-31 10:08:35.681: W/System.err(16946): at android.app.ActivityThread.access$800(ActivityThread.java:144)
01-31 10:08:35.681: W/System.err(16946): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
01-31 10:08:35.681: W/System.err(16946): at android.os.Handler.dispatchMessage(Handler.java:102)
01-31 10:08:35.681: W/System.err(16946): at android.os.Looper.loop(Looper.java:136)
01-31 10:08:35.681: W/System.err(16946): at android.app.ActivityThread.main(ActivityThread.java:5158)
01-31 10:08:35.681: W/System.err(16946): at java.lang.reflect.Method.invokeNative(Native Method)
01-31 10:08:35.681: W/System.err(16946): at java.lang.reflect.Method.invoke(Method.java:515)
01-31 10:08:35.681: W/System.err(16946): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
01-31 10:08:35.681: W/System.err(16946): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
01-31 10:08:35.681: W/System.err(16946): at dalvik.system.NativeStart.main(Native Method)
01-31 10:08:35.681: W/System.err(16946): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
01-31 10:08:35.681: W/System.err(16946): at libcore.io.Posix.open(Native Method)
01-31 10:08:35.681: W/System.err(16946): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
01-31 10:08:35.681: W/System.err(16946): at libcore.io.IoBridge.open(IoBridge.java:393)
01-31 10:08:35.681: W/System.err(16946): ... 18 more
一切都行不通。