zoukankan      html  css  js  c++  java
  • 将一个文本文件的内容按行读出,每读出一行就顺序加上行号,并写入到另一个文件中。

    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 }
  • 相关阅读:
    fastdfs 外网映射问题记录
    fastdfs-nginx下载报错 400
    nginx 代理 websocket
    Jenkins 安装
    实验四.2
    实验四.1
    实验三
    shiyan2
    shiyan1
    作业
  • 原文地址:https://www.cnblogs.com/silenTJ/p/8011921.html
Copyright © 2011-2022 走看看