Example usage for org.apache.commons.io.output LockableFileWriter write

List of usage examples for org.apache.commons.io.output LockableFileWriter write

Introduction

In this page you can find the example usage for org.apache.commons.io.output LockableFileWriter write.

Prototype

public void write(String str) throws IOException 

Source Link

Document

Write the characters from a string.

Usage

From source file:de.ipbhalle.metfrag.tools.Writer.java

/**
 * Write to file and prevent that this file is overwritten by another thread while writing to it.
 * //w  w w  . ja va2 s .c  o  m
 * @param file the file
 * @param content the content
 * 
 * @throws InterruptedException the interrupted exception
 */
public static void writeToFile(String file, String content) throws InterruptedException {
    try {
        LockableFileWriter lfw = new LockableFileWriter(file, true, "/home/swolf/locks/");
        lfw.write(content);
        lfw.close();
    } catch (Exception e) {
        Thread.sleep(10);
        writeToFile(file, content);
    }
}