Scanner类的nextLine方法不仅可以从键盘接收数据,也可以从文件读取数据,且都是以回车为分隔.
1 public class SY64 {
2 public static void main(String[] args) throws Exception {
3 int lineNumber=0;
4 File f1 = new File("d:\\test.txt");
5 File f2 = new File("d:\\test2.txt");
6 PrintStream ps = new PrintStream(f2);
7 Scanner in = new Scanner(f1);
8 String st = null;
9 while(in.hasNext()){
10 st = in.nextLine();
11 ps.println((++lineNumber) + st);
12 }
13 ps.close();
14 in.close();
15 }
16 }
转载于:https://www.cnblogs.com/silenTJ/p/8011921.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)