java程序设计mooc攻略
public class WordsFile {
String path="F:/java/HelloWeb/src/EnglishWords/words.txt";
File file= new File(path);
String str;
public ArrayList<String> getfile() throws IOException {
BufferedReader in=new BufferedReader(new InputStreamReader(new FileInputStream(file),"gbk")) ;
ArrayList<String> arr=new ArrayList<>();
while((str=in.readLine())!=null){
arr.add(str.trim());
}
in.close();
return arr;
}
public static void main(String[] args) throws IOException {
WordsFile w=new WordsFile();
ArrayList<String> arrayList=w.getfile();
for(int i=0;i<arrayList.size();i++){
System.out.println(arrayList.get(i));
}
}
}