public class Solution { public static List<String> allLines = new ArrayList<>(); public static List<String> linesForRemoval = new ArrayList<>(); public static void main(String[] args) { try { new Solution().joinData(); } catch (Exception e){ e.printStackTrace(); } } public void joinData() throws CorruptedDataException { BufferedReader buf= new BufferedReader(new InputStreamReader(System.in)); List<String> filenamelists = new ArrayList<>(); try { filenamelists.add(buf.readLine()); filenamelists.add(buf.readLine()); readFileContent(filenamelists, allLines,linesForRemoval); } catch(Exception e){ } System.out.println("第一个文件内容allLines"); for (String item : allLines) { System.out.print(item+" "); } System.out.println(); System.out.println("第二个文件内容linesForRemoval"); for (String item : linesForRemoval) { System.out.print(item+" "); } synchronized (this) { if (allLines.containsAll(linesForRemoval)) { allLines.removeAll(linesForRemoval); } else { allLines.clear(); throw new CorruptedDataException(); } } try { buf.close(); } catch (IOException e) { e.printStackTrace(); } } private void readFileContent(List<String> filenamelists, List<String> allLines, List<String> linesForRemoval) throws FileNotFoundException { readFileContent(filenamelists.get(0),allLines); readFileContent(filenamelists.get(1),linesForRemoval); } private void readFileContent(String filename1, List<String> lines) throws FileNotFoundException { BufferedReader buf=new BufferedReader(new FileReader(filename1)); System.out.println("读取文件"+filename1 +"内容到列表"); String content=null; try{ while((content=buf.readLine())!=null){ lines.add(content); } } catch (Exception e){ } try { buf.close(); } catch (IOException e) { e.printStackTrace(); } } }