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

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

DataOutputStream和DataInputStream使用的例子

2019-11-18 14:42:21
字體:
來源:轉載
供稿:網友
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(
        "Java2s.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(
        "Java2s.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();
  }
}



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 瑞安市| 惠东县| 陵川县| 罗甸县| 库尔勒市| 合水县| 安塞县| 塔河县| 同德县| 丹江口市| 公主岭市| 聂拉木县| 肥西县| 会东县| 曲水县| 三明市| 崇明县| 上栗县| 南宫市| 榆中县| 突泉县| 海淀区| 南投县| 彭山县| 蓬莱市| 永善县| 南川市| 通化县| 神木县| 濉溪县| 策勒县| 客服| 秀山| 华阴市| 南和县| 阿巴嘎旗| 张家界市| 靖西县| 高淳县| 资溪县| 琼中|