Scrivere subito senza usare la variabile riga incrementa ulteriormente le performance. Pazzesco!!!
codice:
package prova;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
class Esempio {
static void Stampa1(Object[][] matrice, String nome_file) {
String lineSeparator = System.getProperty("line.separator");
try (OutputStream fout = new BufferedOutputStream(
Files.newOutputStream(Paths.get(nome_file)))) {
String riga = "";
for (int i = 0; i < matrice.length; i++) {
riga = "";
for (int j = 0; j < matrice[0].length; j++) {
if (j < matrice[0].length - 1) {
riga = riga + matrice[i][j] + ",";
}
if (j == matrice[0].length - 1) {
riga = riga + matrice[i][j] + lineSeparator;
}
}
fout.write(riga.getBytes());
riga = "";
}
} catch (InvalidPathException e) {
return;
} catch (IOException e) {
return;
}
}
static void Stampa2(Object[][] matrice, String nome_file) {
String lineSeparator = System.getProperty("line.separator");
try (OutputStream fout = new BufferedOutputStream(
Files.newOutputStream(Paths.get(nome_file)))) {
for (int i = 0; i < matrice.length; i++) {
for (int j = 0; j < matrice[0].length; j++) {
if (j < matrice[0].length - 1) {
fout.write((matrice[i][j] + ",").getBytes());
}
if (j == matrice[0].length - 1) {
fout.write((matrice[i][j] + lineSeparator).getBytes());
}
}
}
} catch (InvalidPathException e) {
return;
} catch (IOException e) {
return;
}
}
public static void main(String[] args) throws NoSuchAlgorithmException {
int righe = 600;
int colonne = 600;
Object[][] matrice = new Object[righe][colonne];
for (int i = 0; i < righe; i++) {
for (int j = 0; j < colonne; j++) {
matrice[i][j] = "Indici della cella della matrice: i = " + i
+ " j = " + j;
}
}
long start = System.currentTimeMillis();
Stampa1(matrice, "prova.csv");
long fine = System.currentTimeMillis();
long tempo = fine - start;
System.out.println((double) tempo / 1000);
long start2 = System.currentTimeMillis();
Stampa2(matrice, "prova2.csv");
long fine2 = System.currentTimeMillis();
long tempo2 = fine2 - start2;
System.out.println((double) tempo2 / 1000);
}
}

ti dico solo una cosa:
Output del programma:
10.809
0.967