日期:2014-05-20  浏览次数:20567 次

JAVAIO

  package javaIO;
import java.io.*;
public class IOBug {

/**
 * 功能描述: <br>
 * 〈功能详细描述〉
 *
 * @param args
 * @see [相关类/方法](可选)
 * @since [产品/模块版本](可选)
 */
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("data3.txt")));
out.writeDouble(3.1415926);
out.writeBytes("that was the value of pi");
out.writeBytes("this is pi/2 "+"\n");
out.writeDouble(3.1415926);
out.close();
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("data3.txt")));
BufferedReader inbr = new BufferedReader(new InputStreamReader(in));
System.out.println(in.readDouble());
System.out.println(inbr.readLine());
System.out.println(inbr.readLine()); ///此行
System.out.println(in.readDouble());

}

}


java编程思想4的一个例子,在标注的那一行每次都会把文件里面的对应的那一行内容和后面的double一起读取,产生EOF违例该怎么办
java?IO

------解决方案--------------------
out.writeBytes("that was the value of pi");
        out.writeBytes("this is pi/2 "+"\n");

你这两句写入的只有一行,你可以修改成

out.writeBytes("that was the value of pi\n");
        out.writeBytes("this is pi/2 "+"\n");
------解决方案--------------------
因为第21和22行都是Buffered型的reader