处理流程如下:
1.读入文件内容;
2.调用String的实例方法replace,替换字符串或字符
3.将处理好的内容重新写入文件。读写文件的方法如下: public static String readURL(String urlstr){
StringBuffer sb = new StringBuffer();
try{
URL url = new URL(urlstr);
BufferedReader in = new BufferedReader(
new InputStreamReader(
url.openConnection().getInputStream()));
int tmp = -1;
char temp = ' ';
while((tmp=in.read())!=-1){
temp = (char)tmp;
sb = sb.append(temp);
}
in.close();
}catch(IOException ioe){
ioe.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
return sb.toString();
}
public static void writeToFile(String filename, String msg){
PrintWriter out = null;
try{
out = new PrintWriter(new BufferedWriter(new FileWriter(filename, true)), true);
out.println(msg);
out.close();
}catch(IOException ioe){
System.out.println(ioe);
}
}
1.读入文件内容;
2.调用String的实例方法replace,替换字符串或字符
3.将处理好的内容重新写入文件。读写文件的方法如下: public static String readURL(String urlstr){
StringBuffer sb = new StringBuffer();
try{
URL url = new URL(urlstr);
BufferedReader in = new BufferedReader(
new InputStreamReader(
url.openConnection().getInputStream()));
int tmp = -1;
char temp = ' ';
while((tmp=in.read())!=-1){
temp = (char)tmp;
sb = sb.append(temp);
}
in.close();
}catch(IOException ioe){
ioe.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
return sb.toString();
}
public static void writeToFile(String filename, String msg){
PrintWriter out = null;
try{
out = new PrintWriter(new BufferedWriter(new FileWriter(filename, true)), true);
out.println(msg);
out.close();
}catch(IOException ioe){
System.out.println(ioe);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货