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

📄 stockstorage.java

📁 手机程序股票购买售出的例子
💻 JAVA
字号:
import java.io.DataOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.EOFException;
import java.util.*;


public class StockStorage
{
    public static void writeStock(Stock stock, DataOutputStream outputStream) throws IOException
    {
        // Push the number of shares into a byte array.
        outputStream.writeInt( stock.getNumShares() );

        // Then push the stock name.
        outputStream.writeUTF( stock.getSymbol() );

        // push the stock price
        outputStream.writeInt( stock.getPrice() );
    }

    public static Stock readStock(DataInputStream inputStream) throws IOException
    {
        // read the number of shares
        int numShares = inputStream.readInt();

        // read the stock symbol
        String symbol = inputStream.readUTF();

        // read the stock price
        int price = inputStream.readInt();

        // return a new Stock object
        return new Stock( symbol, numShares, price);
    }
}

⌨️ 快捷键说明

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