Java FileWriter Write saveTemporaryTermFile(File tempLocation, String word, Collection termList)

Here you can find the source of saveTemporaryTermFile(File tempLocation, String word, Collection termList)

Description

Save temporary term file.

License

Open Source License

Parameter

Parameter Description
tempLocation the temp location
word the word
termList the term list

Exception

Parameter Description
IOException Signals that an I/O exception has occurred.

Declaration

public static void saveTemporaryTermFile(File tempLocation,
        String word, Collection<String> termList) throws IOException 

Method Source Code

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

import java.io.BufferedWriter;
import java.io.File;

import java.io.FileWriter;
import java.io.IOException;

import java.util.Arrays;
import java.util.Collection;

public class Main {
    /**/* ww  w .j av  a  2  s .  co m*/
     * Save temporary term file.
     *
     * @param tempLocation the temp location
     * @param word the word
     * @param termList the term list
     * @throws IOException Signals that an I/O exception has occurred.
     */
    public static void saveTemporaryTermFile(File tempLocation,
            String word, Collection<String> termList) throws IOException {
        if (word == null)
            return;
        // if windows OS, check for some speccial files
        if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
            if (Arrays.asList("con", "prn").contains(word))
                return;
        }

        if (!tempLocation.exists())
            tempLocation.mkdirs();
        File f = new File(tempLocation, word);
        BufferedWriter w = new BufferedWriter(new FileWriter(f, true));
        for (String t : termList) {
            w.write(t + "\n");
        }
        w.close();
    }
}

Related

  1. saveStringToFile(String content, File destFile)
  2. saveStringToFile(String filePath, String content, boolean isOverwrite)
  3. saveStringToFile(String fileToSave, String data)
  4. saveStringToFile(String string, String fileName)
  5. saveStringToFile(String text, File fname)
  6. saveText(java.io.File f, String text)
  7. saveTextFile(File file, String text)
  8. saveTextFile(String content, File file, boolean append)
  9. saveTextFile(String contents, File file)