Я действительно застрял в этом. Мне интересно, можно ли исключить все элементы из arraylist при чтении файла? Заранее спасибо!Java ArrayList и FileReader
У меня есть элементы на моей ArrayList (excludelist), как это:
test1
test2
test3
И у меня есть CSV данные о моем файле (readtest), как это:
test1,off
test2,on
test3,off
test4,on
так, что я ожидал чтобы исключить все данные из ArrayList в то время как цикл, то будет выводиться следующим образом:
test4, на
Это мой код:
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;
}
Какая у вас проблема? Что вы сделали для отладки до сих пор? –