- [code]import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- import java.util.Scanner;
- public class DeleteKeyX {
- /**
- * @param args
- * @throws FileNotFoundException
- */
- public static void main(String[] args) throws FileNotFoundException {
-
- if(args.length!=2){
- System.out.println("Usage:java DeleteKeyX keyX fileName");
- System.exit(0);
- }
- File fileName=new File(args[1]);
- if(!fileName.exists()){
- System.out.println("file"+args[1]+"does not exist");
- System.exit(0);
- }
-
- Scanner input=new Scanner(fileName);
- PrintWriter output=new PrintWriter(fileName);
- while(input.hasNext()){
- String s=input.nextLine();
- String s1=s.replaceAll(args[0], "");
- output.println(s1);
- }
-
- input.close();
- output.close();
-
- }
- // TODO Auto-generated method stub
复制代码 [/code] |
|