【发布时间】:2015-06-04 23:28:02
【问题描述】:
我真的很喜欢这个。我想知道是否可以在读取文件时从 arraylist 中排除所有元素?提前谢谢!
我的 arraylist(excludelist) 上有这样的元素:
test1
test2
test3
我的文件(readtest)上有这样的 csv 数据:
test1,off
test2,on
test3,off
test4,on
所以我期望的是在 while 循环中从 arraylist 中排除所有数据,然后输出如下:
测试4,开启
这是我的代码:
String exclude = "C:\\pathtomyexcludefile\\exclude.txt";
String read = "C:\\pathtomytextfile\\test.txt";
File readtest = new File(read);
File excludetest = new File(exclude);
ArrayList<String> excludelist = new ArrayList();
excludelist.addAll(getFile(excludetest));
try{
String line;
LineIterator it = FileUtils.lineIterator(readtest,"UTF-8");
while(it.hasNext()){
line = it.nextLine();
//determine here
}
catch(Exception e){
e.printStackTrace();
}
public static ArrayList<String> getFile(File file) {
ArrayList<String> data = new ArrayList();
String line;
try{
LineIterator it = FileUtils.lineIterator(file,"UTF-8");
while(it.hasNext()){
line = it.nextLine();
data.add(line);
}
it.close();
}
catch(Exception e){
e.printStackTrace();
}
return data;
}
【问题讨论】:
-
你有什么问题?到目前为止,您做了哪些调试工作?
标签: java arraylist bufferedreader