zygimantus
5/13/2015 - 6:49 PM

Some useful Java methods from Input-Output, etc. arrays.

Some useful Java methods from Input-Output, etc. arrays.

/**
 * Writes an array to a file in the working direcotry.
 * 
 * @param fileName filename without path
 * @param array array of any object
 * @return true if success
 */
public boolean writeArrayToFile(String fileName, Object[] array) {
    try (BufferedWriter outputWriter = new BufferedWriter(new FileWriter(fileName))) {
        for (Object o : array) {
            outputWriter.write(o + "\n");
        }
        outputWriter.flush();
        return true;
    } catch (IOException ex) {
        return false;
    }
}