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

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

Introduction

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

Prototype

public LockableFileWriter(File file, boolean append, String lockDir) throws IOException 

Source Link

Document

Constructs a LockableFileWriter.

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.
 * /*from w w w. ja  v a  2  s.  c  om*/
 * @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);
    }
}