무작위 화 된 두 개의 텍스트 파일을 비교하고 두 파일 모두에서 일치하는 행을 인쇄하려고합니다. 파일 1 :Java와 무작위 순서로 두 텍스트 파일 비교
Student1
Student2
Student3
Student4
파일 2 :
Student1
Student2
내 코드는 다음과 같이
Student6
Student1
Student2
나는 출력을 할 수 있습니다.
public static void main(String[] args) throws IOException {
String first = "file1.txt";
String second = "file2.txt";
BufferedReader fBr = new BufferedReader(new FileReader(first));
BufferedReader sBr = new BufferedReader(new FileReader(second));
PrintWriter writer = new PrintWriter("test.txt", "UTF-8");
while ((first = fBr.readLine()) != null) {
String partOne1 = fBr.readLine();
String partTwo1 = sBr.readLine();
while ((second = sBr.readLine()) != null) {
System.out.println(first);
writer.println(first);
break;
}
}
writer.close();
fBr.close();
sBr.close();
첫 번째 파일의 모든 행을'ArrayList'로 읽을 수 있으며 두 번째 파일의 각 문자열이 ArrayList에있는 경우 두 번째로 읽는 동안 http://www.tutorialspot.com/java/util/arraylist_indexof.htm –
Slavik
정렬 및 병합 ... google it up –