【发布时间】:2021-08-29 13:45:29
【问题描述】:
public static void ReadKeyWordsFile() {
try {
ArrayList<String> result = new ArrayList<>();
File file1 = new File("./files/kywrdsOdd.txt");
if(file1.length() == 0){
System.out.println("The files is empty");
}
else{
Scanner scan = new Scanner(file1);
while (scan.hasNextLine()){
result.add(scan.nextLine());
}
System.out.println(result);
for (int counter = 0; counter < result.size(); counter++) {
int l = result.size() -1;
System.out.println(l);
}
scan.close();
}
} catch (FileNotFoundException e) {
//TODO: handle exception
System.out.println("File not found");
e.printStackTrace();
}
}
但这只会返回数组的大小,而不是其中的单词。 我想从数组中的每个单词中获取第一个和最后一个字母的出现
【问题讨论】: