我的网站 http://www.
简单的用replaceAll写了个,不知道可不可以。
package io;
import java.io.*;
import java.util.regex.*;
public class DeleteTest {
public DeleteTest() {
}
/**
* @param args
*/
public static void main(String[] args) throws Throwable{
// TODO Auto-generated method stub
String path = "d:" +java.io.File.pathSeparator + "1.txt";
FileOutputStream fos = new FileOutputStream(path);
fos.write(("Welcome to 210 dormitory, " +
"I am the dormitory head").getBytes());
/*FileInputStream fis = new FileInputStream(path);
byte[] b = new byte[100];
int len = fis.read(b);
for(int i = 0; i < len; i++) {
System.out.print((char)b[i]);
}测试原来输出的*/
BufferedReader bf = new BufferedReader(
new FileReader(path));
//Pattern p = Pattern.compile("dormitory");
String str = bf.readLine();
String writerStr = str.replaceAll(" dormitory", "");
fos.write(writerStr.getBytes());
System.out.print(bf.readLine());
fos.close();
bf.close();
}
}