Here you can find the source of writeFile(double[][] toWrite, String outName)
Parameter | Description |
---|---|
toWrite | is the double[][] to write |
outName | is the full output path |
public static boolean writeFile(double[][] toWrite, String outName)
//package com.java2s; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; public class Main { /**//from w ww .j av a 2 s .com * Write a double[][] with an arbitrary number of columns to a file. * @param toWrite is the double[][] to write * @param outName is the full output path * @return true if successfully completed. */ public static boolean writeFile(double[][] toWrite, String outName) { BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(new File(outName))); for (int l = 0; l < toWrite[0].length; l++) { String line = ""; for (int c = 0; c < toWrite.length; c++) { if (c == toWrite.length - 1) { line += toWrite[c][l]; } else { line += toWrite[c][l] + ","; } } writer.write(line); writer.newLine(); writer.flush(); } } catch (IOException e) { e.printStackTrace(); return false; } finally { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } return true; } /** * Write an int[][] with an arbitrary number of columns to a file. * @param toWrite is an int[][] to write * @param outName is the full output path * @return true if successfully completed. */ public static boolean writeFile(int[][] toWrite, String outName) { BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(new File(outName))); for (int l = 0; l < toWrite[0].length; l++) { String line = ""; for (int c = 0; c < toWrite.length; c++) { if (c == toWrite.length - 1) { line += toWrite[c][l]; } else { line += toWrite[c][l] + ","; } } writer.write(line); writer.newLine(); writer.flush(); } } catch (IOException e) { e.printStackTrace(); return false; } finally { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } return true; } /** * Write an int[][] with an arbitrary number of columns to a file. * @param toWrite is an int[][] to write * @param outName is the full output path * @return true if successfully completed. */ public static boolean writeFile(String[][] toWrite, String outName) { BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(new File(outName))); for (int l = 0; l < toWrite[0].length; l++) { String line = ""; for (int c = 0; c < toWrite.length; c++) { if (c == toWrite.length - 1) { line += toWrite[c][l]; } else { line += toWrite[c][l] + ","; } } writer.write(line); writer.newLine(); writer.flush(); } } catch (IOException e) { e.printStackTrace(); return false; } finally { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } return true; } }