用“”替换文件中的内容达到删除目的
import java.io.InputStreamimport java.io.BufferedReader
import java.io.BufferedWriter
import java.io.FileReader
import java.io.FileWriter
import java.util.Scanner
import java.io.FileNotFoundException
import java.io.IOException
public class zifutihuan
{
protected static void rep(String ch)
{
BufferedReader bis = null
FileWriter bos = null
String s = null
try
{
bis = new BufferedReader(new FileReader("1.txt"))
bos = new FileWriter("2.txt")
while(null != (s = bis.readLine()))
{
s = s.replaceAll(ch,"")
System.out.println(s)
s= s+"\r\n"
bos.write(s)
}
bos.close()
bis.close()
s = null
}
catch(FileNotFoundException e)
{
System.out.println("未找到文件\n")
}
catch(IOException ee)
{
System.out.println("aaa")
}
}
public static void main(String args[])
{
rep("123")
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)