文件未找到? [英] File not found?

查看:75
本文介绍了文件未找到?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个分配,我们给了几个类,其中一个是filereader类,它有一个读取文件的方法,并用包含文件路径的参数(String)进行调用,现在我有一个几个.txt文件,它们与.java文件位于同一文件夹中,因此我认为我可以将file.txt作为文件路径传递(相对于php),但始终会返回文件未发现的异常!

看到给定的类应该正常工作的事实,并且我验证了这些类与.java文件确实位于同一文件夹中的工作区/src中,我必须对filepath字符串做错什么了,但是呢?/p>

这是我的代码:

  private静态最终String fileF ="File.txt";私有静态最终ArrayList< String []>指令F =CreatureReader.readInstructions(fileF); 

解决方案

输入以下内容:

  File here = new File(.");System.out.println(here.getAbsolutePath()); 

代码中的某处.它将打印出程序的当前目录.

然后,只需将文件放在此处,或更改文件路径.

I have an assignment and we have a couple of classes given, one of them is a filereader class, which has a method to read files and it is called with a parameter (String) containing the file path, now i have a couple of .txt files and they're in the same folder as the .java files so i thought i could just pass along file.txt as filepath (like in php, relatively) but that always returns an file not found exception!

Seen the fact that the given class should be working correctly and that i verified that the classes are really in the same folder workspace/src as the .java files i must be doing something wrong with the filepath String, but what?

This is my code:

private static final String fileF = "File.txt";
private static final ArrayList<String[]> instructionsF =
CreatureReader.readInstructions(fileF);

解决方案

Put this:

File here = new File(".");
System.out.println(here.getAbsolutePath());

somewhere in your code. It will print out the current directory of your program.

Then, simply put the file there, or change the filepath.

这篇关于文件未找到?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆