我有以下表格的大清单,出于这个问题的目的,我们将其称为Kraftwerk
匹
屯
牙
友
我还有另一种以下形式的清单,此后称为KomputerLove
兪
yú
部首:入
首尾分解: 人折
罙
shēn
部首:冖
首尾分解: 冖木
叇
dài
部首:厶
首尾分解: 云逮
使用Kraftwerk的作为参考,我想下来大刀KomputerLove这样,如果主要指标KomputerLove,即在此例中就是['兪','罙','叇']
不出现Kraftwerk的,我们消除它。
我没有进行此类搜索和排序操作的丰富经验,什么是实现此目的的最佳方法?应该考虑到,实际上Kraftwerk和KomputerLove两者都稍大一些,大约为1,000的指数。
这些列表的存储方式与您在.txt文件中看到的一样。
这会将所有单个表意文字读入集合。遍历包含线块的文件会复制那些第一行不在表意字符集中的行。
public class Filter {
Set<Character> keys = new HashSet<>();
PrintWriter osw;
void checkAndDump( List<String> lines ) throws Exception {
if( lines.size() >= 1 &&
! keys.contains( lines.get(0).charAt(0) ) ){
for( String s: lines ){
osw.println( s );
}
osw.println();
}
lines.clear();
}
void filter( String inpath, String outpath ) throws Exception {
BufferedReader lr = new BufferedReader( new FileReader( inpath ) );
osw = new PrintWriter( new FileOutputStream( outpath ) );
String line;
List<String> lines = new ArrayList<>();
while( (line = lr.readLine()) != null ){
if( line.length() > 0 ){
lines.add( line );
} else {
checkAndDump( lines );
}
}
checkAndDump( lines );
osw.close();
lr.close();
}
void fillSet( String path ) throws Exception {
BufferedReader br = new BufferedReader( new FileReader( path ) );
String line;
while( (line = br.readLine()) != null ){
if( line.length() > 0 ){
keys.add( line.charAt(0) );
}
}
br.close();
}
public static void main( String[] args ) throws Exception {
Filter f = new Filter();
f.fillSet( "kraftwerk.txt" );
f.filter( "love.txt", "lv.txt" );
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句