//先寫入文件,后讀取
import java.io.*;
public class StreamDemo
{
public static void main(String[] args)
{
?? try
?? {
??? //建立輸出流
??? DataOutputStream out=
???? new DataOutputStream(
????? new BufferedOutputStream(
?????? new FileOutputStream(
??????? "Example.txt")));
??? //寫入一個double類型數(shù)據(jù)
??? out.writeDouble(3.1425926);
??? //寫入一行文本
??? out.writeBytes("This was pi");
??? out.close();
??? //建立輸入流
??? DataInputStream in=
???? new DataInputStream(
????? new BufferedInputStream(
?????? new FileInputStream(
??????? "Example.txt")));
??? //建立輸入Reader
??? BufferedReader reader=
???? new BufferedReader(
????? new InputStreamReader(in));
??? //讀入一個double類型數(shù)據(jù)
??? System.out.println(in.readDouble());
??? //讀入一行文本
??? System.out.println(reader.readLine());
?? }
?? catch(IOException e)
?? {
??? System.out.println(e.toString());
?? }
}
}
posted on 2007-06-18 23:51
jadmin 閱讀(67)
評論(0) 編輯 收藏