游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1454|回复: 0

读写基本数据类型和String wxh zt

[复制链接]

1367

主题

1993

帖子

2118

积分

金牌会员

Rank: 6Rank: 6

积分
2118
发表于 2006-6-16 17:23:00 | 显示全部楼层 |阅读模式

作者:未知  
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);
      out.writeChar('\t');
      out.writeInt(units);
      out.writeChar('\t');
      out.writeChars(descs);
      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();
  }
}


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-24 18:04

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表