import java.io.*;
public class readFile {
public static void main(String[] args){
StringBuffer sb = new StringBuffer();
String text = null;
BufferedReader br = null;
String ss = null;
File f = new File("d:\\findit.txt");
try{
FileInputStream fis = new FileInputStream(f);
InputStreamReader isr = new InputStreamReader(fis);
br = new BufferedReader(isr);
while((text=br.readLine()) != null){
ss = text.replace("abc","123");
sb = sb.append(ss).append(System.getProperty("line.separator"));
}
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}finally{
try{
if(br != null)
br.close();
}catch(IOException e){
e.printStackTrace();
}
}
System.out.println(sb.toString());
System.out.println(
1、读取一个文件,并替换其中指定的字符串为特定字符串
最新推荐文章于 2023-07-18 09:50:08 发布