我知道如何使用 Java
使用 Scanner
和 File 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();
这是我的 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
原文由 word word 发布,翻译遵循 CC BY-SA 4.0 许可协议
存储为字符串:
对于花车: