I know how to read a file with Java
using Scanner
and File IOException, but the only thing I don't know is how to store the text in the files as an array.
Here is a snippet
of my code:
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();
Here is what my KeyWestTemp.txt
file contains:
70.3, 70.8, 73.8, 77.0, 80.7, 83.4, 84.5, 84.4, 83.4, 80.2, 76.3, 72.0
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…