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

voidsaveIntegerNodes2File(Integer[] nodes, String fileName)
save Integer nodes to the fileName
FileWriter fw = null;
fw = new FileWriter(fileName);
String str = "";
if (nodes != null) {
    for (int i = 0; i < nodes.length; i++) {
        str = str + nodes[i];
        str = str + "\n";
} else {
    str = "null";
fw.write(str);
fw.close();
voidsaveIntNodes2File(int[] nodes, String fileName)
save int nodes to the fileName
FileWriter fw = null;
try {
    fw = new FileWriter(fileName);
    String str = "";
    if (nodes != null) {
        for (int i = 0; i < nodes.length; i++) {
            str = str + nodes[i];
            str = str + "\n";
...
voidsaveList(String listName, Set list)
save List
try (BufferedWriter bw = new BufferedWriter(new FileWriter(new File(listName)))) {
    for (String line : list) {
        bw.write(line);
        bw.write("\n");
booleansaveListStringToFile(String filePath, List listString)
save List String To File
System.out.println("Save translation to file " + filePath);
try {
    StringBuffer content = new StringBuffer();
    for (String str : listString) {
        content.append(str + System.getProperty("line.separator"));
    FileWriter writer = new FileWriter(filePath);
    writer.write(content.toString());
...
voidsaveListToFile(ArrayList list, String filePath)
save List To File
File file = new File(filePath);
try {
    FileWriter fw = new FileWriter(file);
    for (int i = 0; i < list.size(); i++) {
        String s = list.get(i);
        fw.write(s + "\n");
        System.out.println(s);
    fw.close();
} catch (FileNotFoundException fnfe) {
    fnfe.printStackTrace();
} catch (IOException ioe) {
    ioe.printStackTrace();
voidsaveMap(Map map, String filePath)
save Map
PrintWriter pw = null;
try {
    pw = new PrintWriter(new BufferedWriter(new FileWriter(filePath)), true);
} catch (IOException e) {
    e.printStackTrace();
    exit(1);
for (Entry<K, V> entry : map.entrySet()) {
...
voidsaveMap(String filename, Map map)
Saves a map to a file with the given name -- by default, calls the corresponding saveMap() function with a "reverse" parameter of false.
saveMap(filename, map, false);
voidsaveMappingFile(File mappingFile, Map messageMap)
save Mapping File
FileWriter fw = new FileWriter(mappingFile);
for (String message : messageMap.keySet()) {
    Integer id = messageMap.get(message);
    fw.append(message).append("=").append(id.toString()).append("\n");
fw.close();
voidsaveMeasures(String appDirPath, String fileName, double[] measures)
save Measures
String filePath = appDirPath + File.separator + fileName;
PrintWriter pw = null;
boolean autoFlush = true;
try {
    pw = new PrintWriter(new BufferedWriter(new FileWriter(filePath)), autoFlush);
} catch (IOException e) {
    e.printStackTrace();
    exit(1);
...
voidsaveMetaClassToFile(File baseDir, String clazzDef, String metaPackageName, Class fromClazz)
save Meta Class To File
String clazzPcg = packageNameHelper(fromClazz, metaPackageName);
String[] pcg = clazzPcg.split("\\.");
File dest = baseDir;
for (String p : pcg) {
    dest = new File(dest, p);
    if (!dest.exists())
        dest.mkdir();
dest = new File(dest, classNameHelper(fromClazz) + ".java");
FileWriter write = new FileWriter(dest);
write.write(clazzDef);
write.close();