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

voidsaveToFile(String location, File tempFile)
save To File
FileWriter fw = new FileWriter(tempFile.getAbsolutePath(), true); 
fw.write(location + "\n");
fw.close();
voidsaveToFile(String path, String line)
save To File
BufferedWriter bw = null;
try {
    bw = new BufferedWriter(new FileWriter(path, true));
    bw.write(line);
    bw.newLine();
} catch (Exception localException) {
    try {
        if (bw != null) {
...
FilesaveToFile(String prefix, Reader input)
save To File
File file;
BufferedWriter bw = null;
try {
    file = File.createTempFile(prefix, null);
    bw = new BufferedWriter(new FileWriter(file));
    BufferedReader inputReader = new BufferedReader(input);
    String thisLine;
    while ((thisLine = inputReader.readLine()) != null) {
...
voidsaveToJson(Object object, String file)
save To Json
Gson gson = new GsonBuilder().setPrettyPrinting().create();
try {
    Writer writer = new FileWriter(file);
    writer.write(gson.toJson(object));
    writer.close();
} catch (IOException e) {
    e.printStackTrace();
FilesaveToTempFile(File folder, String content, String fileType)
save To Temp File
String uuid = UUID.randomUUID().toString();
File f = new File(folder, uuid + "." + fileType);
BufferedWriter out = new BufferedWriter(new FileWriter(f));
out.write(content);
out.close();
return f;
voidsaveTreeStructuredGroupList(ArrayList> treeStructuredGroupList, String filePath)
save Tree Structured Group List
PrintWriter pw = null;
try {
    pw = new PrintWriter(new BufferedWriter(new FileWriter(filePath)), true);
} catch (IOException e) {
    e.printStackTrace();
    System.exit(1);
for (ArrayList<T> list : treeStructuredGroupList) {
...
voidsaveTxt(String line, String filename, boolean isEndSave)
save Txt
try {
    FileWriter file = new FileWriter(filename, isEndSave);
    BufferedWriter writer = new BufferedWriter(file);
    writer.write(line);
    writer.newLine();
    writer.close();
} catch (IOException e) {
    e.printStackTrace();
...
voidsaveTxtFile(String fileName, String content)
save Txt File
File file = new File(fileName + ".txt");
try (FileWriter fw = new FileWriter(file, true)) {
    fw.write(content + "\n");
    fw.flush();
} catch (IOException e) {
    e.printStackTrace();