Java扫描程序。为什么运行时无法找到文件?难道我做错了什么。我知道该文件存在于目录中,并且其中有几行文本。它是一个没有扩展名的文件,但即使我添加一个带扩展名的文件,它仍然无法运行。
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package brownK_OSpgm2.java;
import java.io.*;
import java.util.*;
/**
*
* @author kirkt
*/
public class brownK_OSpgm2 {
/**
* @param args the command line arguments
*/
private Scanner x;
public void openFile() {
try
{
x = new Scanner(new File("RAMerrors8x4"));
}
catch(Exception e){
System.out.println("Could not find file darn it");
}
}
public void readFile()
{
while(x.hasNext()){
String a = x.next();
String b = x.next();
String c = x.next();
System.out.printf("%s %s %s\n", a,b,c);
}
}
public void closeFile() {
x.close();
}
public static void main(String[] args) {
System.out.println ("Hello World");
brownK_OSpgm2 r = new brownK_OSpgm2();
r.openFile();
r.readFile();
r.closeFile();
}
}