日期:2014-05-20 浏览次数:20768 次
String str = null; String strflg = null; String str1 = "!"; String str2 = "@"; File fi = new File ("你的文档.TXT"); ReaderFile rf = new ReaderFile (fi); BufferedReader br = new Reader(); //遍历文本,取出每一行。 while(str = br.readline()!= null ) { //取出第一个字符。 strflg = str.substring(0,1); if(strflg.equals(str1)) { str = str.replace("!","@"); System.ou.println(str); } else {System.ou.println(str);} }
------解决方案--------------------
找找中文的jdk api文档看看吧!我初学!呵呵
------解决方案--------------------
简单方法不会,就会笨的
先把a.txt(原始数据)哪出来,改完后放入b.txt,然后再把b.txt写回去
import java.io.*; public class Csdn1{ public static void main(String[] args) { BufferedReader bd = null; BufferedWriter bw = null; try { bd = new BufferedReader(new FileReader("F:\\sushuai\\23\\a.txt")); bw = new BufferedWriter(new FileWriter("F:\\sushuai\\23\\b.txt")); String str1 = null; StringBuffer str2 = null; while((str1 = bd.readLine()) != null) { // System.out.println(str1); if (str1.length() == 0 ) { } else if (str1.charAt(0) == '@'){ } else if (str1.charAt(0) == '!') { str2 = new StringBuffer(str1); str2.setCharAt(0,'@'); str1 =str2.substring(0); } bw.write(str1,0,str1.length()); bw.newLine(); } bd.close(); bw.close(); }catch(IOException e) { e.printStackTrace(); } try { bd = new BufferedReader(new FileReader("F:\\sushuai\\23\\b.txt")); bw = new BufferedWriter(new FileWriter("F:\\sushuai\\23\\a.txt")); String str3 = null; while((str3 = bd.readLine())!= null) { bw.write(str3,0,str3.length()); bw.newLine(); } bd.close(); bw.close(); } catch(IOException e1) { e1.printStackTrace(); } } }
------解决方案--------------------
学习。
LZ 举的例子 太个例了