public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(new File("C:/book.txt"))); BufferedWriter bw = new BufferedWriter(new FileWriter("C:/text.txt")); String text = ""; String tmpReader = null; while( null != (tmpReader=reader.readLine()) ){ String[] split = tmpReader.split("--"); for( int i=0 ; i<split.length ; i++ ){ text = text+split[i]+"##"; } text = text.substring(0, text.length()-2)+System.getProperty("line.separator"); bw.write(text); text = "" ; } bw.close(); reader.close(); }
将原文本内容中--换为##
单纯的读写操作
public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(new File("C:/book.txt"))); BufferedWriter bw = new BufferedWriter(new FileWriter("C:/text.txt")); String tmpReader = null; while( null != (tmpReader=reader.readLine()) ){ bw.write(tmpReader); } bw.close(); reader.close(); } }
java 技术交流群 57388149