Example usage for org.apache.commons.io FileUtils writeStringToFile

List of usage examples for org.apache.commons.io FileUtils writeStringToFile

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils writeStringToFile.

Prototype

public static void writeStringToFile(File file, String data, String encoding) throws IOException 

Source Link

Document

Writes a String to a file creating the file if it does not exist.

Usage

From source file:com.sap.prd.mobile.ios.mios.XCodeTest.java

private static void filterPoms(File projectDirectory) throws IOException {
    Set<File> pomFiles = new HashSet<File>();
    getPomFiles(projectDirectory, pomFiles);

    for (File pomFile : pomFiles) {
        String pom = FileUtils.readFileToString(pomFile);
        pom = pom.replaceAll("\\$\\{xcode.maven.plugin.version\\}", getMavenXcodePluginVersion());
        FileUtils.writeStringToFile(pomFile, pom, "UTF-8");
    }//  www  .ja  v a  2s  .co  m
}

From source file:de.atomfrede.tools.evalutation.util.PreProcessor.java

public static void replaceWhiteSpacesWithComma(File inputFile) throws IOException {
    List<String> inputLines = FileUtils.readLines(inputFile);
    List<String> outputlines = new ArrayList<String>();
    for (String line : inputLines) {
        String outLine = line.replaceAll("\\s+", ",");
        outLine += "\n";
        outputlines.add(outLine);/*from  ww  w  . jav a2  s . c  o m*/
    }
    int line = 0;
    for (String outputLine : outputlines) {
        if (line == 0)
            FileUtils.writeStringToFile(inputFile, outputLine, false);
        else
            FileUtils.writeStringToFile(inputFile, outputLine, true);
        line++;

    }
}

From source file:com.thoughtworks.go.config.ConfigMigrator.java

public static GoConfigMigration migrate(final File configFile) {
    ConfigElementImplementationRegistry registry = ConfigElementImplementationRegistryMother.withNoPlugins();
    String content = "";
    try {//from   w  w w .j a  v  a  2  s  .co m
        content = FileUtils.readFileToString(configFile, UTF_8);
    } catch (IOException e1) {
    }

    GoConfigMigration upgrader = new GoConfigMigration(new TimeProvider(), registry);
    //TODO: LYH & GL GoConfigMigration should be able to handle stream instead of binding to file
    String upgradedContent = upgrader.upgradeIfNecessary(content);
    try {
        FileUtils.writeStringToFile(configFile, upgradedContent, UTF_8);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return upgrader;
}

From source file:com.github.cc007.buildoffmanagermaven.utils.PersistencyHelper.java

public static boolean saveBuildOff() {
    try {//from   w ww. j ava 2  s.c o m
        File boFile = new File(BuildOffManager.getPlugin().getDataFolder(), "BuildOff.json");
        Gson gson = new GsonBuilder().registerTypeAdapter(Location.class, new LocationAdapter()).create();
        String boString = gson.toJson(BuildOffManager.getPlugin().getActiveBuildOff());
        FileUtils.writeStringToFile(boFile, boString, Charset.defaultCharset());
        return true;
    } catch (IOException ex) {
        Logger.getLogger(PersistencyHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    return false;
}

From source file:jetbrick.tools.chm.reader.AnchorNameManager.java

public static void addAnchor(File file, String encoding) throws IOException {
    String html = FileUtils.readFileToString(file, encoding);
    html = html.replace('$', '\uFFE5');

    Pattern p = Config.style.getAnchorNameRegex();
    Matcher m = p.matcher(html);/*  w ww. ja va2 s.  c  om*/

    int findCount = 0;
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        findCount++;
        String anchor = m.group(1);
        // String oldAnchor = m.group();
        String oldAnchor = "<A HH=\"1\" NAME=\"" + anchor + "\">";
        String newAnchor = "<A HH=\"1\" NAME=\"" + getNewAnchorName(anchor) + "\"></A>";
        m.appendReplacement(sb, newAnchor + oldAnchor);
    }
    m.appendTail(sb);

    System.out.println("addAnchor(" + findCount + ") : " + file);

    if (findCount > 0) {
        html = sb.toString().replace('\uFFE5', '$');
        FileUtils.writeStringToFile(file, html, encoding);
    }
    html = null;
}

From source file:alilibs.AliFile.java

public static void appendString(String filename, String str) throws IOException {
    File f = new File(filename);

    FileUtils.writeStringToFile(f, str, true);

    ///*  w ww  .  j av a 2  s  . c  o  m*/

}

From source file:com.epam.spring.core.logger.FileEventLogger.java

@Override
public void logEvent(Event event) {
    try {/*  w  w w  .ja  v a 2s  . c o m*/
        FileUtils.writeStringToFile(file, event.toString(), true);
    } catch (IOException ex) {
        Logger.getLogger(FileEventLogger.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:it.cnr.ilc.ilcioutils.IlcInputToFile.java

/**
 * Creates a file with the content read from string
 * @param string the String with the content is
 * @return a File with the content from the URL
 */// w w  w.  j  a v  a 2  s .  c o m
public static File createAndWriteTempFileFromString(String string) {
    File tempOutputFile = null;
    String encoding = "UTF-8";
    String message;
    try {
        tempOutputFile = File.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX);
        FileUtils.writeStringToFile(tempOutputFile, string, encoding);

    } catch (IOException e) {
        message = String.format("Error in accessing String %s %s", string, e.getMessage());
        Logger.getLogger(CLASS_NAME).log(Level.SEVERE, message);
    }
    return tempOutputFile;

}

From source file:com.thoughtworks.go.util.TestFileUtil.java

public static File writeStringToTempFileInFolder(String directoryName, String fileName, String contents)
        throws Exception {
    File folderToCreate = tempFiles.createUniqueFolder(directoryName);
    File fileToCreate = new File(folderToCreate, fileName);
    folderToCreate.mkdirs();/* w w w .  j a va 2s  . c  om*/
    FileUtils.writeStringToFile(fileToCreate, contents, UTF_8);
    fileToCreate.deleteOnExit();
    folderToCreate.deleteOnExit();
    return fileToCreate;
}

From source file:com.z2data.files.WriteOperations.java

/**
 * Write error URL in file//from  w  ww .  ja  va  2  s. c o  m
 * 
 * @param outputPath
 * @param URL
 * @param errorMessage
 */
public static void writeErrorData(String outputPath, String URL, String errorMessage) {
    File file = null;
    try {
        file = new File(outputPath);

        if (!file.exists()) {
            file.createNewFile();
        }

        String errorFileName = "ERRORS_URLS_" + file.getName();
        File errorFile = null;
        if (file.getParent() == null || file.getParent().isEmpty()) {
            errorFile = new File(errorFileName);
        } else {
            errorFile = new File(file.getParent() + errorFileName);
        }

        if (!errorFile.exists()) {
            errorFile.createNewFile();
        }
        FileUtils.writeStringToFile(errorFile, URL + "\t" + errorMessage, true);
        FileUtils.writeStringToFile(errorFile, System.lineSeparator(), true);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}