다음과 같이 구분 된 이름과 비밀번호가있는 텍스트 파일이 있습니다.텍스트 파일을 읽을 때 문제가 발생했습니다.
사용자가 올바른 사용자 이름과 암호를 제공하면 로그인 페이지에서 환영 페이지로 이동합니다. 그러나 나는 이것을 제대로 얻지 못하고있다. 내가 얻을 수있는 출력은
user1
pwd1
inside try
user1
pwd1
true
welcome user1
user2
pwd2
false
not equal
입니다. 아래 코드는 아래와 같습니다. 이 작업을 수행하려면 ... 하나를 발견 한 후
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.regex.*;
import com.sun.org.apache.xalan.internal.xsltc.compiler.Pattern;
public class TextFile {
/**
* @param args
*/
public void getNamePwd(String name, String pwd) {
// TODO Auto-generated method stub
System.out.println(name);
System.out.println(pwd);
String[] splitVals=null;
try{
System.out.println("inside try");
String strLine;
BufferedReader br = new BufferedReader(new FileReader("D:\\test\\text.txt"));
while((strLine=br.readLine())!=null){
splitVals=strLine.split(":");
for(int i=0;i<splitVals.length;i=i+2){
System.out.println(splitVals[i].toString());
System.out.println(splitVals[i].toString());
String nameUser=splitVals[i].toString();
String passWord=splitVals[i+1].toString();
System.out.println(name.equals(nameUser));
if((name.equals(nameUser))&&(pwd.equals(passWord))){
System.out.println("welcome"+name);
}
else{
System.out.println("not equal");
}
}
}
}catch(Exception e){
}
}
}
저를 도와주세요 ... 난 당신이 이름을 찾고 중지 할 것인지 의심
사실 이것은 'for' 루프를 깨고 실제로'while '루프가 깨지는 것이 아니라는 점에 유의하십시오. 내 대답을 보라. – aioobe