输入到文件当中去,判断遇到end就结束,那位帮忙改改

来源:百度知道 编辑:UC知道 时间:2024/07/02 08:53:58
public class FileIn {
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader buf = new BufferedReader(isr);
FileOutputStream fos = new FileOutputStream("test.txt");
//String s1 = fos.toString();
String s = buf.readLine();
while (true) {
if (s.equals("end")) {
fos.close();
}
else {
fos.write(buf.read());
}
}
}
}
lpbls
你的答案实现起来还是不行 我早就试过的

while (not s.equals("end"))
{
fos.write(buf.read());
s = buf.readLine();
}
fos.close();

************
那就请你关注一下读取buf是否正确;判断='end'是否正确(比如'end'前后是否有空格等)。