Hi Guys/gals,
I have atext file that I am tring to read to an array. So far I have it so it reads each line however I cannot work out how to read each "word" so to speak. I need the space in my file to be the split. I know i need to use the split(); function but I am unsure where to put it.
If you could let me know where and how I can improve the code i have currenty that would be great. I am not sure if its 'good'...
cheers.
Text file looks like this : (There are more lines but always 6 objects with
John doe 1 2 3 Smith
Jane doe 1 2 3 Smith
import java.io.*;
import java.util.Vector;
public class reader {
public static void main (String args[]){
String ln;
String[] apps;
Vector lines = new Vector();
try{
FileReader fr=new FileReader("applicants.txt");
BufferedReader br=new BufferedReader(fr);
while((ln=br.readLine())!=null){
lines.addElement(ln);
}
apps = new String[lines.size()];
for (int i = 0; i < apps.length; i++) {
apps[i] = (String) lines.elementAt(i);
// Test to see if the array works.
System.out.println(apps);
}
}
catch(IOException e) {
System.out.println("Error: " + e);
}
}
}