1.把浮點數寫入文件
import java.io.*;
public class FileOutputDemo
{
public static void main(String[] args)
{
?? FileOutputStream out;
?? DataOutputStream p;
?? try
?? {
??? out = new FileOutputStream("myfile.txt");
??? p = new DataOutputStream(out);
??? p.writeDouble(3);
??? p.writeDouble(4);
??? p.writeDouble(5);
??? p.close();
?? }
?? catch(Exception e)
?? {
??? System.err.println("Error writing to file");
?? }
}
}
2.從文件中讀取浮點數
import java.io.*;
public class FileInputDemo
{
public static void main(String[] args)
{
?? if(args.length==1)
?? {
??? try
??? {
???? FileInputStream f = new FileInputStream(args[0]);
???? DataInputStream in = new DataInputStream(f);
???? while(in.available() != 0)
???? {
????? System.out.println(String.valueOf(in.readDouble()));
???? }
???? in.close();
??? }
??? catch(Exception e)
??? {
???? System.out.println("File input Erroe!");
??? }
?? }
?? else
??? System.out.println("Invalid parametres");
}
}
posted on 2007-05-28 00:25
jadmin 閱讀(91)
評論(0) 編輯 收藏