我知道如何Java使用Scanner和文件IOException 读取文件,但我唯一不知道的是如何将文本作为数组存储在文件中.
这是snippet我的代码:
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();
Run Code Online (Sandbox Code Playgroud)
这是我的KeyWestTemp.txt文件包含的内容:
70.3, 70.8, 73.8, …Run Code Online (Sandbox Code Playgroud)