📄 testvector.java
字号:
import java.io.*;
import java.util.*;
class TestVector implements java.io.Serializable{
private Vector vect=new Vector();
public void add(Object obj){
this.vect.add(obj);
}
public void print(){
System.out.println(this.vect);
}
public static void main(String[] args){
try {
/* 将对象写到一个文件里 */
FileOutputStream objfile = new FileOutputStream("testvector.obj");
/* 创建一个输出流 */
ObjectOutputStream p = new ObjectOutputStream(objfile);
/* 创建一个TestVector对象 */
TestVector tv =new TestVector();
/*给Vector写入几String个对象*/
tv.add("One");
tv.add("Two");
tv.add("Three");
p.writeObject(tv); // 把tv写入流
p.flush();
objfile.close(); // 关闭文件对象
} catch (Exception e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -