public static void writeMatrixToFile(Matrix m, String filename) {
try (FileWriter writer = new FileWriter(filename, false)) {
String strForWrite = "";
for (int i = 1; i < m.getRowCount(); i++) {
for (int j = 1; j < m.getColCount(); j++) {
strForWrite += m.get(i, j) + " ";
}
strForWrite += "\n";
}
writer.write(strForWrite);
writer.flush();
} catch (IOException e) {
e.printStackTrace();
} catch (MatrixIndexException e) {
e.printStackTrace();
}
}
public static Matrix loadMatrixFromFile(Matrix m, String filename) {
try (FileWriter writer = new FileWriter(filename, false)) {
String strForWrite = "";
writer.write(String.valueOf(m.getRowCount()));
writer.write("\n");
writer.write(String.valueOf(m.getColCount()));
writer.write("\n");
for (int i = 1; i < m.getRowCount(); i++) {
for (int j = 1; j < m.getColCount(); j++) {
strForWrite += m.get(i, j) + " ";
}
strForWrite += "\n";
}
writer.write(strForWrite);
writer.flush();
} catch (IOException e) {
e.printStackTrace();
} catch (MatrixIndexException e) {
e.printStackTrace();
} catch (Exception e) {
}