[英]Read Certain words from text file java
So i have a text file ( tagged.txt
) full of different sentences.所以我有一个充满不同句子的文本文件(
tagged.txt
)。 What I am looking to do is read this text file into Java, and extract specific words from this file.我要做的是将这个文本文件读入 Java,并从这个文件中提取特定的单词。
eg例如
Sentence : I went to the shop to buy a new pair of trainers
一句话:
I went to the shop to buy a new pair of trainers
If the sentence has the words shop
, buy
, or trainers
in it, I would like that sentence to equal an opinion.如果句子中有单词
shop
、 buy
或trainers
,我希望这句话等于一个意见。
I have created a list of the words in a text file ( words.txt
), in which I would like to stream against the tagged.txt
file.我在文本文件 (
words.txt
) 中创建了一个单词列表,我想在其中对tagged.txt
文件进行流式传输。
I just wanted to know if there is a way of implementing this in Java.我只是想知道是否有办法在 Java 中实现这一点。
words.txt
and store in an array and sort it using Arrays.sort(arr)
.words.txt
读取单词并存储在一个数组中,然后使用Arrays.sort(arr)
对其进行Arrays.sort(arr)
。tagged.txt
line by line and store it in a String
. tagged.txt
读取tagged.txt
的行并将其存储在String
。 Then you could use split()
to split the line into different words and store the words in an array.split()
将行拆分为不同的单词并将这些单词存储在数组中。binarysearch
method to search through the words from the words array.binarysearch
方法从 words 数组中搜索单词。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.