package stringserial2;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.StringTokenizer;
/**
*
* @author Ko Hyang Gu
*/
class StringData implements Serializable{
String str = null;
public StringData(String str){
this.str = str;
}
public String getData(){
return this.str;
}
}
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
// TODO code application logic here
int len = args.length;
int index = 0;
StringBuffer sb = new StringBuffer();
while(len>0){
sb.append(args[index]);
sb.append(" ");
index++;
len--;
}
StringData sd = new StringData(sb.toString());
FileOutputStream fo = new FileOutputStream("a.data");
ObjectOutputStream oo = new ObjectOutputStream(fo);
oo.writeObject(sd);
oo.close();
FileInputStream fi = new FileInputStream("a.data");
ObjectInputStream oi = new ObjectInputStream(fi);
StringData sdi = (StringData)oi.readObject();
oi.close();
String temp = sdi.getData();
System.out.println("deserial string "+temp);
StringTokenizer st = new StringTokenizer(temp);
int num = st.countTokens();
System.out.println("deserial string num "+num);
String[] sa = new String[num];
while(st.hasMoreTokens()){
System.out.println("deserial string value "+st.nextToken());
}
}