I'm trying to write a program for homework that opens a file that is given by the string and reads a series of comma separated integer values into an array, which it then returns.
import java.util.Arrays;
...
int[] readVector(String filename) throws IOException {
File f = new File(filename);
FileOutputStream fos = new FileOutputStream(f, true);
PrintWriter pw = new PrintWriter(fos);
pw.println("");
pw.close();
FileReader fr = new FileReader(f);
BufferedReader bfr = new BufferedReader(fr);
while (true) {
String s = bfr.readLine();
if (s == null) {
break;
}
System.out.println(s);
}
bfr.close();;
return NOIDEA;
}
Consider this...
Matrix m = new Matrix();
System.out.println(Arrays.toString(m.readVector("vector.txt"))); // print "[1, 2, 3, 4]"