国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

讀寫基本數據類型和String

2019-11-18 14:45:34
字體:
來源:轉載
供稿:網友
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class DataIODemo1 {
  public static void main(String[] args) throws IOException {
    DataOutputStream out = new DataOutputStream(new FileOutputStream(
        "j2medev.txt"));

    double[] PRices = { 19.99, 9.99, 15.99, 3.99, 4.99 };
    int[] units = { 12, 8, 13, 29, 50 };
    String[] descs = { "Java", "Source ", "and",
        "Support."};

    for (int i = 0; i < prices.length; i++) {
      out.writeDouble(prices[i]);
      out.writeChar('/t');
      out.writeInt(units[i]);
      out.writeChar('/t');
      out.writeChars(descs[i]);
      out.writeChar('/n');
    }
    out.close();

    // read it in again
    DataInputStream in = new DataInputStream(new FileInputStream(
        "j2medev.txt"));

    double price;
    int unit;
    String desc;
    double total = 0.0;

    try {
      while (true) {
        price = in.readDouble();
        in.readChar(); // throws out the tab
        unit = in.readInt();
        in.readChar(); // throws out the tab
        desc = in.readLine();
        System.out.println( unit );
        System.out.println( desc );
        System.out.println( desc );
        total = total + unit * price;
      }
    } catch (EOFException e) {
    }
    in.close();
  }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 两当县| 烟台市| 体育| 东阳市| 新邵县| 铁岭县| 蒙阴县| 江津市| 玉屏| 阿坝县| 三原县| 新源县| 通山县| 伽师县| 集安市| 新兴县| 合山市| 无棣县| 章丘市| 龙岩市| 手机| 甘孜县| 荆州市| 云阳县| 鹤峰县| 革吉县| 大洼县| 德州市| 成武县| 乌兰察布市| 长葛市| 西畴县| 清水县| 浏阳市| 仙居县| 黄山市| 绥化市| 屯昌县| 从化市| 信宜市| 望江县|