⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objectstreams.java

📁 it contains the practical programs in our college
💻 JAVA
字号:
import java.io.*;import java.math.BigDecimal;import java.util.Calendar;public class ObjectStreams {    static final String dataFile = "invoicedata";    static final BigDecimal[] prices = {         new BigDecimal("19.99"),         new BigDecimal("9.99"),        new BigDecimal("15.99"),        new BigDecimal("3.99"),        new BigDecimal("4.99") };    static final int[] units = { 12, 8, 13, 29, 50 };    static final String[] descs = { "Java T-shirt",            "Java Mug",            "Duke Juggling Dolls",            "Java Pin",            "Java Key Chain" };    public static void main(String[] args)         throws IOException, ClassNotFoundException {         ObjectOutputStream out = null;        try {            out = new ObjectOutputStream(new                    BufferedOutputStream(new FileOutputStream(dataFile)));            out.writeObject(Calendar.getInstance());            for (int i = 0; i < prices.length; i ++) {                out.writeObject(prices[i]);                out.writeInt(units[i]);                out.writeUTF(descs[i]);            }        } finally {            out.close();        }        ObjectInputStream in = null;        try {            in = new ObjectInputStream(new                    BufferedInputStream(new FileInputStream(dataFile)));            Calendar date = null;            BigDecimal price;            int unit;            String desc;            BigDecimal total = new BigDecimal(0);            date = (Calendar) in.readObject();            System.out.format ("On %tA, %<tB %<te, %<tY:%n", date);            try {                while (true) {                    price = (BigDecimal) in.readObject();                    unit = in.readInt();                    desc = in.readUTF();                    System.out.format("You ordered %d units of %s at $%.2f%n",                            unit, desc, price);                    total = total.add(price.multiply(new BigDecimal(unit)));                }            } catch (EOFException e) {}            System.out.format("For a TOTAL of: $%.2f%n", total);        } finally {            in.close();        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -