我试图从与源代码位于同一文件夹的计算机读取文件,并在运行代码时说:文件不存在 您能帮助我吗?从主机读取文件
import java.io.*;
import java.util.*;
public class Lotto1 {
static String[][] arr;
static String name, number;
public static void main(String[] args) throws IOException {
File f = new File("D:\\Filipe\\Project Final\\src\\database_lotto.txt.txt");
Scanner s;
try {
s = new Scanner(f);
BufferedReader reader = new BufferedReader(new FileReader(f));
int lines = 0;
while(reader.readLine() != null) {
lines++;
}
reader.close();
arr = new String[lines][3];
int count = 0;
//while theres still another line
while(s.hasNextLine()) {
arr[count][0] = s.next() + "" + s.next();
arr[count][1] = s.next();
arr[count][2] = s.next();
count++;
}
} catch(FileNotFoundException ex) {
System.out.println("File does not exist");
}
database_lotto.txt.txt?你确定它不应该是database_lotto.txt? – stevenelberger 2013-04-06 22:39:43
是不是这个问题 - http://stackoverflow.com/questions/15854085/reading-a-file-from-the-computer – 2013-04-06 22:43:21
即使与database_lotto.txt这是同样的问题。 – user1831131 2013-04-06 22:44:05