Vector_ReadFile.htm
 
The file to read

Using Vector to read a file

import java.io.*;
import java.util.*;// Arrays.sort

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();
try{
System.out.print("Please Enter a File name: ");
file_name = br.readLine();
pp.method_1(file_name);
}//try
catch(NumberFormatException e)
{ System.out.println("data was blank");}

}
}
class Process
{
//vector is stretchable
public Process(){System.out.println("Default) constructor");}
public void method_1(String str)throws IOException
{
String file_name="", line;
//ArrayList buff = new ArrayList();
Vector buff = new Vector();
BufferedReader Source = new BufferedReader( new FileReader( str));
try {
//for (int i =0; i <buff.length; i++)
while ((line = Source.readLine()) != null)
{
buff.add(line);
}
} catch (IOException e) { System.out.println("could not read at process"); }
finally{ Source.close(); System.out.println("Soruce closed"); }
System.out.println(buff);
Iterator it = buff.iterator();
System.out.println("---Iteratring Array List----");
while(it.hasNext())
{
System.out.println("\t" + it.next());
}
}
}