发布网友 发布时间:2024-09-15 03:16
共3个回答
热心网友 时间:2024-10-18 18:59
我试过了。可以的,你多加一句测试一下:
String x="0",y="0";
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader("resources/position.txt"));
} catch (FileNotFoundException fnfe) {
System.out.println("Sorry, can't read "+"resources/positon.txt");
}
try {
try {
String line;
while ( (line = reader.readLine()) != null ) {
int a=-1,b=-1;
a=line.indexOf('x');
if(a!=-1)
x=line.substring(a+1);
b=line.indexOf('y');
if(b!=-1)
y=line.substring(b+1);
//多加入的测试语句:
System.out.println("String x is: "+x+"\n"+"String y is: "+y);
}
} finally {
reader.close();
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
如果不行,我怀疑是你的文件名真的是取错了
热心网友 时间:2024-10-18 18:52
看下文件路径对不对啊
热心网友 时间:2024-10-18 18:52
"resources/position.txt"改成"./resources/position.txt"试试,不然用绝对路径好了。