I am trying to create a program that reads from a txt file (this is the only thing in the file "5,5,5,0"). Then I want to take that information, put it in an array, then use that array to fill an array list. Then use that arraylist to write infromation into the file.
Here is what I have so far in my class file:
import java.io.*;
import java.util.Scanner;
import java.util.ArrayList;
public void setMoney() throws IOException {
File moneyFile = new File ("Money.txt");
Scanner moneyScan = new Scanner(moneyFile);
String [] tokens = moneyFile.split(",");
ArrayList<Integer> money = new ArrayList<Integer>(Arrays.asList(tokens));
for(int i=0;i<tokens.length;i++){
money.append(tokens[i]);
}
String s = Integer.toString(tokens[i]);
FileOutputStream fos = new FileOutputStream("Money.txt");
fos.write(money);
fos.close();
}
Money.append
is giving me this error:
error: cannot find symbol
money.append(tokens[i]);
^
symbol: method append(String) location: variable money of type ArrayList
moneyFile.split
is giving me this error:
error: cannot find symbol
String [] tokens = moneyFile.split(",");
^
symbol: method split(String)
location: variable moneyFile of type File