posts - 495,  comments - 11,  trackbacks - 0

          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 閱讀(94) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 胶州市| 临安市| 分宜县| 临猗县| 肃宁县| 信丰县| 遂宁市| 阳泉市| 金溪县| 江津市| 易门县| 江孜县| 榆林市| 于田县| 时尚| 陇南市| 江口县| 梁平县| 鹤壁市| 克山县| 大名县| 贵德县| 民权县| 娱乐| 大新县| 平定县| 永福县| 山西省| 保靖县| 白山市| 独山县| 武邑县| 扬州市| 湟中县| 固镇县| 鱼台县| 宜良县| 班戈县| 宜川县| 秦安县| 社会|