Dobrogo vremia sutok,
Zadacha sravnit dva txt i zapisat v tretij txt raznye strochki
package Main;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class doublefail {
public static void main(String[] args) throws IOException {
List<String> lt= new ArrayList<String>();;
File file = new File ("C:/Users/Jevgenij/Desktop/o.txt");
FileInputStream fis = null;
//pervyj fail
try{
fis= new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String content;
while ((content = br.readLine()) != null) {
lt.add(content);}
}
catch (IOException e) {
e.printStackTrace();
} finally {
fis.close();
}
// vtoroj fail
List<String> gt= new ArrayList<String>();;
File file3 = new File ("C:/Users/Jevgenij/Desktop/k.txt");
FileInputStream fis3 = null;
try{
fis3= new FileInputStream(file3);
BufferedReader bt = new BufferedReader(new InputStreamReader(fis3));
String content;
while ((content = bt.readLine()) != null) {
gt.add(content);}
}
catch (IOException e) {
e.printStackTrace();
} finally {
fis3.close();
}
// output stream
int t=0;
OutputStream file2 = new FileOutputStream( "C:/Users/Jevgenij/Desktop/l.txt" );
OutputStream of = new BufferedOutputStream(file2);
ObjectOutputStream oss= new ObjectOutputStream (of);
try{
Iterator it=lt.iterator();
while(it.hasNext()){
String value=(String)it.next();
Iterator kt=gt.iterator();
while(kt.hasNext()){
//r++;
String o=(String)kt.next();
if (value.equals(o)) {
t++;
}
if(t==0){
System.out.println(value);
oss.writeBytes(value);
oss.write(System.getProperty("line.separator").getBytes());
t=0;}
}
}
} finally {
oss.close();
}
}
}