面试题SMKJ——no.1
生活随笔
收集整理的這篇文章主要介紹了
面试题SMKJ——no.1
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
文件input.txt是一個文本文件,每一行有多列(用空格分隔)。keyword.conf是一個關鍵詞配置文件,每一行是一個詞。請找出文件input.txt中第一列包含keyword.conf中任意一個關鍵詞的文本行并輸出。
示例
輸入:
文件input.txt內容:
abc xxx
bcd xxx
def xxx
xyz xxx
?
文件keyword.conf內容:
bc
eft
?
輸出(打印到標準輸出):
abc xxx
bcd xxx
package com.shumei;import java.io.*; import java.util.ArrayList; import java.util.List;/*** @author George* @description**/ public class One {public static void main(String[] args) throws IOException {BufferedReader br = new BufferedReader(new FileReader("d:/input.txt"));BufferedReader br2 = new BufferedReader(new FileReader("d:/keyword.conf"));String line = "";String line2 = "";List<String> list = new ArrayList<>();List<String> list2 = new ArrayList<>();while ((line = br.readLine()) != null){String[] strings = line.split(" ");list.add(strings[0]);}while ((line2 = br2.readLine()) != null){list2.add(line2);}for (String s1 : list2) {if (list.contains(s1)){list.remove(s1);}}for (String s : list) {System.out.println(s + " xxx");}br.close();} }?
?
總結
以上是生活随笔為你收集整理的面试题SMKJ——no.1的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何使用IO流将数字输出到文件中
- 下一篇: 重游Scala02