黑马程序员技术交流社区

标题: 执行完以后没内容了,为什么? [打印本页]

作者: abc张强8    时间: 2014-7-2 22:10
标题: 执行完以后没内容了,为什么?
  1. [code]import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.io.PrintWriter;
  4. import java.util.Scanner;

  5. public class DeleteKeyX {

  6.         /**
  7.         * @param args
  8.         * @throws FileNotFoundException
  9.         */
  10.         public static void main(String[] args) throws FileNotFoundException {
  11.                
  12.                 if(args.length!=2){
  13.                         System.out.println("Usage:java DeleteKeyX keyX fileName");
  14.                         System.exit(0);
  15.                 }
  16.                 File fileName=new File(args[1]);
  17.                 if(!fileName.exists()){
  18.                         System.out.println("file"+args[1]+"does not exist");
  19.                         System.exit(0);
  20.                 }
  21.                
  22.                 Scanner input=new Scanner(fileName);
  23.                 PrintWriter output=new PrintWriter(fileName);

  24.                 while(input.hasNext()){
  25.                         String s=input.nextLine();
  26.                         String s1=s.replaceAll(args[0], "");
  27.                         output.println(s1);
  28.                 }
  29.                
  30.                 input.close();
  31.                 output.close();
  32.                
  33.                 }
  34.                 // TODO Auto-generated method stub


复制代码
[/code]
作者: 马到成功2014    时间: 2014-7-2 22:28
你先在最上面输出args[0],就知道了




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2