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 阅读(89)
评论(0) 编辑 收藏