Java OutputStreamWriter Write saveCache()

Here you can find the source of saveCache()

Description

save Cache

License

Open Source License

Declaration

public static boolean saveCache() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.io.FileOutputStream;

import java.io.OutputStreamWriter;

import java.util.Iterator;
import java.util.Map;

public class Main {
    private static Map<String, Integer> cache;

    public static boolean saveCache() {
        String data = "";
        Iterator<String> keyIterator = cache.keySet().iterator();
        while (keyIterator.hasNext()) {
            String key = (String) keyIterator.next();
            int value = cache.get(key);
            data += key + "," + value + "\n";
        }/*from   ww w. java 2s .  c  o m*/
        File f = new File("cache.map");
        if (f.exists())
            f.delete();
        try (FileOutputStream fo = new FileOutputStream(f);
                OutputStreamWriter out = new OutputStreamWriter(fo, "UTF-8")) {
            out.write(data);
            out.flush();
            return true;
        } catch (Exception e) {
            System.err.println(e);
            return false;
        }
    }
}

Related

  1. save(String fileContent, File file, String encoding)
  2. save(String text, File out)
  3. saveDocument(String path, String textToWrite)
  4. saveFile(File file, String whatToSave, String encoding)
  5. saveFile(final File file, final String content)
  6. saveFile(String content, File f, String encoding)