import java.io.*;
public class BinaryIODemo {
public static void main(String[] args) throws IOException
{
try
{
DataOutputStream out = new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream("Data.txt")));
out.writeBoolean(true);
out.writeDouble(3.1415926);
out.writeChars("That was PI\n");
out.writeBytes("That was PI\n");
out.close();
DataInputStream in = new DataInputStream(
new BufferedInputStream(
new FileInputStream("Data.txt")));
BufferedReader buffer = new BufferedReader(
new InputStreamReader(in));
System.out.println(in.readBoolean());
System.out.println(in.readDouble());
System.out.println(buffer.readLine());
System.out.println(buffer.readLine());
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
程序运行结果是:true
3.1415926
为什么System.out.println(buffer.readLine());和System.out.println(buffer.readLine());没有输出内容来啊?
楼主, 我运行了你的代码, 有内容输出啊. 结果为:
true
3.1415926
T h a t w a s P I
That was PI
我和二楼的运行结果一样啊
^_^,我也有输出呀
true
3.1415926
T h a t w a s P I
That was PI
我也试了 可以输出阿
搂主看看你有没有生成data.txt这个文件?
我的结果也同楼上,没问题啊!
我也运行了,前面两位都一样啊!
我的也有结果啊,和上面的一样啊