gpt4 book ai didi

Java 不知道在哪里可以找到 .csv 文件,我应该把它放在哪里?

转载 作者:行者123 更新时间:2023-11-30 11:09:08 24 4
gpt4 key购买 nike

我有一个名为 v1.csv 的 csv 文件,它位于主项目目录中。当我尝试读取燃料时,java 似乎从未找到它。为了将文件读入二维数组,我使用了 opencsv 和扫描仪解决方案,但这两种方法都不起作用。我应该如何让 java 知道在哪里可以找到文件?

扫描仪解决方案:

BufferedReader reader = new BufferedReader(new FileReader(
"v1.csv"));

Opencsv 解决方案:

CSVReader reader = new CSVReader(new FileReader("v1.csv"));

Opencsv 备用:

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

全部都不行。

最佳答案

为了在 Java 中访问文件,它应该位于 classpath 上或用 absolute path 引用.

关于Java 不知道在哪里可以找到 .csv 文件,我应该把它放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28254641/

24 4 0