Java Utililty Methods FileWriter Write

List of utility methods to do FileWriter Write

Description

The list of methods to do FileWriter Write are organized into topic(s).

Method

booleansave(File file, String content)
Saves the content to a file.
boolean result;
BufferedWriter writer;
writer = null;
try {
    writer = new BufferedWriter(new FileWriter(file));
    writer.write(content);
    writer.flush();
    result = true;
...
booleansave(File file, String text)
Method for saving the String into a file.
try {
    BufferedWriter bw = new BufferedWriter(new FileWriter(file));
    bw.write(text);
    bw.close();
    return true;
} catch (IOException e) {
    e.printStackTrace();
return false;
booleansave(File pFile, String pString)
save
if (pFile == null)
    return false;
FileWriter out = null;
BufferedWriter buf = null;
try {
    out = new FileWriter(pFile);
    buf = new BufferedWriter(out);
    buf.write(pString);
...
voidsave(final String content, final String file)
Write in file - overwrite.
FileWriter out = null;
try {
    out = new FileWriter(file, false);
    out.write(content);
} catch (IOException e) {
    e.printStackTrace();
} finally {
    if (out != null) {
...
voidsave(List list, String REPO)
DOCUMENT ME!
try {
    FileWriter out = new FileWriter(REPO);
    for (String s : list) {
        out.write(s);
        out.write(NEWLINE);
    out.close();
} catch (IOException e) {
...
voidsave(Map map, String path)
save
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, Integer> read : map.entrySet()) {
    for (int i = 0; i < read.getValue(); i++) {
        sb.append(">").append(i).append("\n").append(read.getKey()).append("\n");
saveFile(path, sb.toString());
voidsave(String fileName, Object o)
save
Gson gson = new GsonBuilder().setPrettyPrinting().create();
try (FileWriter out = new FileWriter(fileName);) {
    out.write(gson.toJson(o));
voidsave(String fileName, String dataToSave)
Saves the text to a file on the users machine.
try {
    FileWriter fw = new FileWriter(fileName);
    fw.write(dataToSave);
    fw.close();
} catch (IOException e) {
    e.printStackTrace();
booleansave(String modelo, String filename)
save
try {
    BufferedWriter out = new BufferedWriter(new FileWriter(filename));
    out.write(modelo);
    out.close();
} catch (IOException ex) {
    return false;
return true;
...
booleansave(String targetDir, String filename, String textToSave)
Helper for saving a text to file
File dir = new File(targetDir);
if (!(dir.exists() || dir.mkdirs())) {
    System.err.println("Error: couldn't create directory " + targetDir + "!");
    return false;
File file = new File(targetDir + "/" + filename);
file.delete();
try {
...