Can someone help me optimize my java code, (new to java)

Im not sure i need to count the lines or create a new BufferedReader just to count lines.

Anyone know a better way?

import java.util.*;

import java.io.*;

publicclass Login22{

publicstaticboolean validateUser (String inUsername, String inPassword)throws IOException, FileNotFoundException

{

BufferedReader myIn =new BufferedReader(new FileReader("persondata.txt"));

BufferedReader read =new BufferedReader(new FileReader("persondata.txt"));

String line ="";

String[] words;

String file =null;

int countLines = 0;

String username=null;

String password=null;

boolean confirm =false;

while((file = read.readLine()) !=null){

countLines ++;

}

for (int a=0; a<countLines; a++){

line = myIn.readLine();

words = line.split ("\\t+");

if(inUsername.equals(words[2]) && inPassword.equals(words[4])){

confirm =true;

break;

}

}

return confirm;// Retunerar true or false till servern

}

}

persondata.txt

F鰎namnEfternamnPersonnummerTiml鰊L鰏enord

BoEk650326-2781105abc123

NisseSvensson801202-122378,5aqw183

HassenKhameli790412-3423120jonas

LisaAndersson760203-343485kla12

JakobNilsson820603-444483sdlksq

EliziReveiro790923-125690lksfj

gegegeg222

Message was edited by:

HolaJawn>

[2701 byte] By [HolaJawna] at [2007-11-26 20:44:17]
# 1
And why exactly were you counting those lines again?Get rid of that for loop and just use the string you read in your while loop test to validate.
Peetzorea at 2007-7-10 2:04:59 > top of Java-index,Java Essentials,New To Java...