 <p>Try the following idea: </p> <pre><code>try { File file = new File(path); FileWriter writer = new FileWriter(file); BufferedWriter output = new BufferedWriter(writer); for (int[] array : matrix) { for (int item : array) { output.write(item); output.write(" "); } output.write("\n"); } output.close(); } catch (IOException e) { } </code></pre>