📄 writeobject.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -