我是一个java新手,正在寻找一些帮助读取文件的帮助。这是我正在使用的代码。在Java中读取.txt文件的问题
来源:
public void Escanear()
{
Scanner sc=new Scanner(new File("inicio.txt"));
while(sc.hasNext())
{
String token = sc.next();
if (token.equals("Pared"))
{
int i=sc.nextInt();
int j=sc.nextInt();
_mat=new Pared[i][j];
}
else if(token.equals("Fantasma"))
{
int i=sc.nextInt();
int j=sc.nextInt();
_mat=new Fantasma[i][j];
}
}
}
错误:
C:\Users\User\Documents\Jorge\Clases UNIMET\Trimestre 5\Estructuras de Datos\Proyecto Pacman\JuegoPacman.java:28: error: unreported exception FileNotFoundException; must be caught or declared to be thrown
Scanner sc=new Scanner(new File("inicio.txt"));
我已经导入java.io.FileNotFoundException,则和我已经打开.txt文件,它位于同一文件夹中因为我正在编译的类......如何解决它的任何想法?谢谢。
给出正确的道路。像'D:/ jmd/sample.log'。 – Arung 2012-02-11 21:53:00
请在这里发布文件的完整路径,它是否包含任何国家的符号? – 2012-02-11 22:07:56