I have this code below.What i'm trying to do is read a text file which every line has Strings separated by tabs.For example (name \t country \t id \t content) where \t is the tab.Then i want to print only the 2nd column of each line.I'm trying split the whole line to tokens but it works fine only for the 1st line of the file and then it throws ArrayIndexOutOfBoundsException. Also it works perfect when i try to print only the 1st column (tokens[0]) but not for tokens[1] which I need.So what am I need to do to get the 2nd columns of each line?
public static void main(String[] args) throws FileNotFoundException, IOException
{
FileInputStream fis=new FileInputStream("a.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(dis)) ;
String line;
while ((line = br.readLine()) != null)
{
String[] tokens=line.split("\\t");
System.out.println(tokens[1]);
}
fis.close();
}