我读取一个这样的文件 1 2 ,当前目录是 ${workspace_loc:Welcome/src} ,文件名是a.txt。
3 4
下面是我写的程序代码:import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;public class Wang
{
public static void main(String[] args) throws FileNotFoundException
{
// int oneInt =0;
// int twoInt =0;
Scanner in = new Scanner(new File("a.txt"));
while (in.hasNext())
{
String line = in.nextLine();
char one = line.charAt(0);
char two = line.charAt(2);
System.out.println("one: " + one);
System.out.println("two: " + two);
}
}
} // oneInt = oneInt + Integer.parseInt(one + "");
//
// }
// System.out.println(oneInt / 2);
// }
//
//}整个程序运行结果是0,而除去注释的部分,运行结果是任何东西都没有,不知道哪里出了问题,求高手解答!
3 4
下面是我写的程序代码:import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;public class Wang
{
public static void main(String[] args) throws FileNotFoundException
{
// int oneInt =0;
// int twoInt =0;
Scanner in = new Scanner(new File("a.txt"));
while (in.hasNext())
{
String line = in.nextLine();
char one = line.charAt(0);
char two = line.charAt(2);
System.out.println("one: " + one);
System.out.println("two: " + two);
}
}
} // oneInt = oneInt + Integer.parseInt(one + "");
//
// }
// System.out.println(oneInt / 2);
// }
//
//}整个程序运行结果是0,而除去注释的部分,运行结果是任何东西都没有,不知道哪里出了问题,求高手解答!
System.out.println("文件路径:" + file.getAbsolutePath() ); //看看文件路径对不对
Scanner in = new Scanner(file) ;
one: 1
two: 2
包含注释结果是:
one: 1
two: 2
0