- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStream;
- public class Test1 {
- public static void main(String[] args) throws IOException {
- File f = new File("F:\\新建文本文档.txt");
- StringBuilder sb = new StringBuilder();
- FileWriter fw = new FileWriter(f);
- InputStream in = System.in;
- String temp = null;
- int x=0;
- while(true){
- x=in.read();
- temp = sb.toString();
- if(x=='\r')
- continue;
- if (x=='\n')
- {
- fw.write(temp);
- if("over".equals(temp))
-
- break;
- sb.delete(0,sb.length());
- System.out.println(temp);
- }else{
-
- sb.append((char)x);
- }
- }
- fw.flush();
- fw.close();
- }
-
- }
复制代码 我帮你把循环条件改了下,可以通过了,代码如下: |