Hello, I want to read a file, file.txt that contains word pairs like this...
mot;word
oui;yes
utiliser;use
comment;how
After reading this file.txt , I want to split this text and put the French words in an ArrayList and the English words in an another ArrayList.
Thanks in advance...
解决方案
public static void main(String[] args) {
List list = new ArrayList();
List frenchList = new ArrayList();
List englishList = new ArrayList();
File file = new File("C:/dico.txt");
if(file.exists()){
try {
list = Files.readAllLines(file.toPath(),Charset.defaultCharset());
} catch (IOException ex) {
ex.printStackTrace();
}
if(list.isEmpty())
return;
}
for(String line : list){
String [] res = line.split(";");
frenchList.add(res[0]);
englishList.add(res[1]);
}
}
With this code you have de french word in the list "frenchlist" and the english words in the list "englishlist"