大剑无锋之研发笔试题(一)
生活随笔
收集整理的這篇文章主要介紹了
大剑无锋之研发笔试题(一)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文件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.george;import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List;/*** @author George* @description* 文件input.txt是一個文本文件,每一行有多列(用空格分隔)。keyword.conf是一個關鍵詞配置文件,* 每一行是一個詞。請找出文件input.txt中第一列包含keyword.conf中任意一個關鍵詞的文本行并輸出。**/ public class Develop1 {public static void main(String[] args) throws IOException {BufferedReader brInput = new BufferedReader(new FileReader("./data/input.txt"));BufferedReader brKey = new BufferedReader(new FileReader("./data/keyword"));String str = "";List<String> keys = new ArrayList<>();while((str = brKey.readLine()) != null){keys.add(str);}while((str = brInput.readLine()) != null){ // System.out.println(str);String[] splits = str.split(" ");for (String key : keys) {if (splits[0].contains(key)){System.out.println(str);}}}brInput.close();brKey.close();} }?
總結
以上是生活随笔為你收集整理的大剑无锋之研发笔试题(一)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MYSQL查表的字段名称,字段类型,字段
- 下一篇: 提问题