문자열에서 데이터를 분리하는 방법은 여기에서 읽었습니다. 대부분의 경우 놀라운 결과를 냈습니다.문자열에서 데이터 나누기
공백, 사용자 이름, MD5 해시, "에 둘러싸인 일반 텍스트 암호"로 구분 된 줄에 네 개의 섹션이있는 자격 증명 파일에서 데이터를 가져 오려고합니다. 마지막으로 역할이 있습니다. .split을 사용하여 내가 필요로하는 것이라고 생각하기 시작했지만, 세 번째 또는 두 번째 항목에는 가끔씩 분할을 필터링해야하는 공간이 있습니다. 어떤 아이디어?
credentialLine에서 분리됩니다 라인 :
griffin.keyes 108de81c31bf9c622f76876b74e9285f "알파벳 수프"사육사
FileInputStream credentialsFile = null;
Scanner inFS = null;
String credFile = ".\\src\\authenticationsystem\\credentials.txt";
System.out.println("\nOpening file credentials.txt");
credentialsFile = new FileInputStream(credFile);
inFS = new Scanner(credentialsFile);
String credentialLine = inFS.nextLine();
System.out.println(credentialLine);
System.out.println("Closing file credentials.txt\n");
credentialsFile.close();
String[] userCreds = credentialLine.split("\\s+");
String userCred = userCreds[0];
String userMD = userCreds[1];
String userPass = userCreds[2];
String userRole = userCreds[3];
이 문서에서 너무 빨리 다루지 마십시오. 일반 텍스트 암호에 ** 공백이없는 경우 ** 실패합니다. 어쨌든 거기에는 공간이있을 때만 있습니다. – DevilsHnd
authenticationsystem.AuthenticationSystem.main (AuthenticationSystem.java:48) C : \ Users \ Anna \ AppData \ Local \ NetBeans \ Cache \ 8.2에있는 3 \t 스레드 "main"아래 예외가 받았습니다. \ executor-snippets \ run.xml : 53 : Java가 반환되었습니다 : 1 BUILD FAILED (총 시간 : 2 초) – Ghostey
@DevilsHnd 네 말이 맞아, 나는 그것을 고려하지 않았다. – Titus