我知道如何使用Java的Scanner和File IOException读取文件,但我不知道如何将文件中的文本存储为数组。
以下是我的代码片段:
这是我的
以下是我的代码片段:
public static void main(String[] args) throws IOException{
// TODO code application logic here
// // read KeyWestTemp.txt
// create token1
String token1 = "";
// for-each loop for calculating heat index of May - October
// create Scanner inFile1
Scanner inFile1 = new Scanner(new File("KeyWestTemp.txt"));
// while loop
while(inFile1.hasNext()){
// how can I create array from text read?
// find next line
token1 = inFile1.nextLine();
这是我的
KeyWestTemp.txt
文件的内容:70.3, 70.8, 73.8, 77.0, 80.7, 83.4, 84.5, 84.4, 83.4, 80.2, 76.3, 72.0
new LinkedList<String>();
在这种情况下使用链表的理由是什么? - njzk2inFile1
扫描器(因此关闭输入文件)。虽然在main
中只做这个可能没关系,但在更大的应用程序中可能会成为一个问题。 - SergGr