Java Utililty Methods OutputStreamWriter Write

List of utility methods to do OutputStreamWriter Write

Description

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

Method

voidsave(String fileContent, File file, String encoding)
Saves a string to a text file.
FileOutputStream fos = new FileOutputStream(file);
OutputStreamWriter writer = new OutputStreamWriter(fos, encoding);
try {
    writer.write(fileContent);
    writer.flush();
} finally {
    fos.close();
voidsave(String text, File out)
Creates file with given text
BufferedWriter bw = new BufferedWriter(
        new OutputStreamWriter(new DataOutputStream(new FileOutputStream(out))));
bw.write(text);
bw.close();
booleansaveCache()
save Cache
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";
File f = new File("cache.map");
...
voidsaveDocument(String path, String textToWrite)
Method to save a document on a path
File f = new File(path);
Writer out = null;
try {
    f.createNewFile();
    out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "UTF-8"));
    out.write(textToWrite);
    out.close();
} catch (IOException e) {
...
voidsaveFile(File file, String whatToSave, String encoding)
save File
if (file.isDirectory()) {
    throw new IllegalArgumentException("File " + file + " should not be a directory");
try {
    BufferedWriter output = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream(file), encoding));
    output.write(whatToSave);
    output.close();
...
voidsaveFile(final File file, final String content)
save File
FileOutputStream fos = new FileOutputStream(file);
final Writer writer = new OutputStreamWriter(fos, "UTF-8");
writer.write(content);
writer.close();
fos.close();
voidsaveFile(String content, File f, String encoding)
Method to save String as file in specified encoding/.
try (Writer output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), encoding))) {
    output.write(content);
    output.flush();
voidsaveFile(String fname, String text, String encode)
save File
OutputStreamWriter ow = new OutputStreamWriter(new FileOutputStream(fname), encode);
ow.write(text);
ow.close();
voidsaveFile(String path, String msg)
save File
FileOutputStream fos = new FileOutputStream(new File(path));
OutputStreamWriter osw = new OutputStreamWriter(fos);
osw.write(msg);
osw.flush();
osw.close();
voidsaveListString(List list, String filename)
save List String
BufferedWriter out;
try {
    out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "UTF8"));
    for (int i = 0; i < list.size(); i++) {
        out.write((String) list.get(i) + "\n");
    out.close();
} catch (IOException ex) {
...