Hashtable: reading data from Hastable using input streams.
File to read

Example

import java.io.*;
import java.util.Enumeration;
import java.util.Hashtable;

public class Test_This {
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
//C:/myjava/eclipse_classic/eclipse/ch2/test/index.html
Process p1 = new Process();
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String file_name ="";
Process pp = new Process();
pp.method_1();
}
}
class Process
{
String[] first = {"A","B","D","C","F","E","F"};
String[] second = {"1","2","3","5","4","5","6"};
public Process(){System.out.println("Default) constructor");}
public void method_1()throws IOException
{
System.out.println("Key Values");
Hashtable ht = new Hashtable();
String str = "", str1="";
for(int i = 0; i < first.length; i++)
{
ht.put(first[i], second[i]);

}
System.out.println(ht);
Enumeration e = ht.keys();
System.out.println("-----------");
System.out.println("Key Values");
while(e.hasMoreElements())
{
str = (String)e.nextElement();

System.out.println(str + "\t " +ht.get(str));
}
try
{
FileOutputStream fout = new FileOutputStream("C:/myjava/my_temp/demo.serial");
System.out.println("--destination accessed");
ObjectOutputStream out = new ObjectOutputStream(fout);
System.out.println("--wrting data----");
out.writeObject(ht);
System.out.println("--closing stream--");
out.close();

}//try block
catch (Exception ec){System.out.println(ec); }
finally {
System.out.println("Adios: All OK");
File_Reader fr = new File_Reader();
fr.method_do();
}
}
}
class File_Reader
{
public void method_do()throws IOException
{
try
{
System.out.println("--read destination accessed");
FileInputStream fread = new FileInputStream("C:/myjava/my_temp/demo.serial");
System.out.println("--streaming read----");
ObjectInputStream in = new ObjectInputStream(fread);
System.out.println("--putting in a Hastable bufer----");
Hashtable htr = (Hashtable)in.readObject();
System.out.println("--reading Hash with toString()----");
System.out.println(htr.toString());
}//try block
catch (Exception ec){System.out.println(ec); }
finally {
System.out.println("Adios: All read");
}

}
}