public void getWord() throws Exception { BufferedReader in = new BufferedReader(new FileReader( ".\\javaIO\\fail1.txt")); PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter( ".\\javaIO\\fail1_2.txt"))); String s = ""; int line = 0; while ((s = in.readLine()) != null) { System.out.println("现在进行到第" + ++line + "行" + s); StringReader sr = new StringReader(s); String word = ""; char c = (char) sr.read(); while (c != ',') { word += c; c = (char) sr.read(); } pw.print(word); pw.print("\t"); System.out.print(word + "\t"); c = (char) sr.read(); System.out.println(c); while ((int) c != -1) { word += c; c = (char) sr.read(); } pw.print(word); pw.println(); System.out.println(word); sr.close(); } in.close(); pw.close(); } |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |