I know how to read a file using Java using Scanner and File IOException, but the only thing I don't know is how to save text in files as an array.
Here is the snippet 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 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
source share