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

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

使用ObjectStream 進(jìn)行寫(xiě)入和讀出操作

2019-11-18 14:42:10
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
使用ObjectStream 進(jìn)行寫(xiě)入和讀出操作
點(diǎn)擊查看大圖



/* From http://java.sun.com/docs/books/tutorial/index.Html */


import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class DataIOTest2 {
  public static void main(String[] args) throws IOException {

    // write the data out
    ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
        "invoice1.txt"));

    double[] PRices = { 19.99, 9.99, 15.99, 3.99, 4.99 };
    int[] units = { 12, 8, 13, 29, 50 };
    String[] descs = { "Java T-shirt", "Java Mug", "Duke Juggling Dolls",
        "Java Pin", "Java Key Chain" };

    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
    ObjectInputStream in = new ObjectInputStream(new FileInputStream(
        "invoice1.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("You've ordered " + unit + " units of "
            + desc + " at $" + price);
        total = total + unit * price;
      }
    } catch (EOFException e) {
    }
    System.out.println("For a TOTAL of: $" + total);
    in.close();
  }
}


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 青海省| 陵川县| 内江市| 长沙县| 修文县| 霍邱县| 湘潭市| 丰原市| 德化县| 沂南县| 始兴县| 南漳县| 梧州市| 曲阜市| 奇台县| 临桂县| 吉林市| 阜康市| 德化县| 乡宁县| 麦盖提县| 兰州市| 渑池县| 内丘县| 叙永县| 屯留县| 文成县| 桂阳县| 兴安县| 富源县| 科技| 仙居县| 东源县| 宁波市| 莱西市| 泰兴市| 麻城市| 临高县| 财经| 历史| 镶黄旗|