writeobject.java
来自「java 完全探索的随书源码」· Java 代码 · 共 38 行
JAVA
38 行
import java.io.*;import java.util.*;// This class writes out a date object and a hash table object// to a file called "writeme" using an ObjectOutputStream.public class WriteObject{ public static void main( String[] args ) { // Create a hash table with a few entries Hashtable writeHash = new Hashtable(); writeHash.put("Leader", "Moe"); writeHash.put("Lieutenant", "Larry"); writeHash.put("Stooge", "Curly"); try { // Create an output stream to a file called "writeobject.txt" FileOutputStream fileOut = new FileOutputStream( "writeobject.txt" ); // Open an output stream filter on the file stream ObjectOutputStream objOut = new ObjectOutputStream( fileOut ); // Write out the current date and the hash table objOut.writeObject( new Date() ); objOut.writeObject( writeHash ); // Close the stream objOut.close(); } catch ( IOException ex ) { ex.printStackTrace(); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?