日期:2014-05-20 浏览次数:20930 次
package com.wwy.io;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class CopyFile {
/**
* @param args
*/
@SuppressWarnings("unchecked")
public static void main(String[] args) {
// TODO Auto-generated method stub
List<List> mylist = read();
List<List> my = read();
List<String> l1 = repetition(mylist.get(0), mylist.get(1));
List<String> l2 = repetition(my.get(1),my.get(0));
write(l1,l2);
System.out.println("ok");
}
public static List<List> read(){
File f1 = new File("D:\\a\\test1.txt");
File f2 = new File("D:\\a\\test2.txt");
List<List> mylist = new ArrayList<List>();
List<String> l1 = new ArrayList<String>();
List<String> l2 = new ArrayList<String>();
String str1 = "";
String str2 = "";
BufferedReader br1 = null;
BufferedReader br2 = null;
try {
br1 = new BufferedReader(new FileReader(f1));
br2 = new BufferedReader(new FileReader(f2));
while((str1 = br1.readLine() ) != null ){// (str2 = br2.readLine()) != null){
l1.add(str1);
}
while((str2 = br2.readLine()) != null){
l2.add(str2);
}
mylist.add(l1);
mylist.add(l2);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
if(br1 != null){
br1.close();
br1 = null;
}
if(br2 != null){
br2.close();
br2 = null;
}
} catch (Exception e2) {
// TODO: handle exception
}
}
return mylist;
}
public static List<String> repetition(List<String> l1,List<String> l2){
for(int i = 0; i < l1.size(); i++){
for(int j = 0;j<l2.size();j++){
if(l2.get(j) .equals(l1.get(i))){
System.out.println("sdgsad======" + l1.get(i));
l1.remove(i);
}
}
}
/*for(String str1 :l1){
System.out.println("str1 : " + str1);
for(String str2 : l2){
System.out.println("str2 : " + str2);
if(str1.equals(str2)){
System.out.println("222 2 " + str1);
//int index = l1.indexOf(str1);
l1.remove(str1);
System.out.println("============ " + l1.remove(str1) );
}
}
}*/
return l1;