hey everyone,
well i have made a method that would return array of string. the strings would be obtained from the file(employee.txt) every 4th line in the file contains employees loginID i need to store those ids in to one array and then return it.
here is the code of what i did so far
public String[] displyName(){
int num = 0;
int idLine =2;
String str="";
String[] loginID=new String[20];
try
{ BufferedReader bufeinp = new BufferedReader( new FileReader("employee.txt"));
while ((str = bufeinp.readLine()) !=null)
{
if(num == idLine)
{ int i =0;
i++;
loginID[i] =str;
idLine=idLine+4;
}
++num;
}
bufeinp.close();
}
catch(IOException e)
{ System.err.println("Exception: " + e.getMessage());
System.exit(1);
}
return loginID;
}
the problem is when i call the method im unable to retrieve any data stored in array from this method...
this is how i tried to call the values from displyName() method but this gave me null returns
String[] array = displyName();
for(int i= 0; i<array.lenght; i++){
System.out.println(array[0]);
}
how would i be able to call this method and use loginID array ?
is there anything i am doing wrong in this method?
any suggestions would be greatly appreciated?
thank you