简体   繁体   中英

java.io.IOException: Couldn't get lock for

Get error as

"java.io.IOException: Couldn't get lock for ..\\log\\abc.log", not sure why this happen.

Can somebody help me out? Thank you

        logger = LogManager.getLogManager().getLogger(className);
        FileHandler logFile = new FileHandler(file);

        // create txt Formatter
        SimpleFormatter formatterTxt = new SimpleFormatter();
        logFile.setFormatter(formatterTxt);         
        logger.addHandler(logFile);

@Catheryan

I also had the same issue. For me issue was:

private static final String FILE_PATH="/home/jeril/Logs.log";
handler = new FileHandler(FILE_PATH);

FILE_PATH was WRONG

This issue is a long standing bug in FileHandler (reported way back in March 2005, in Java 4):

JDK-6244047 : impossible to specify directories to logging FileHandler unless they exist

Quoting from the description of this bug:

If you specify a patern to the FileHandler that contains directories that don't currently exist then the FileHandler will fail to initialise even if the directories can be created

Its mentioned that it has been fixed in Java 8. For versions earlier than 8, the workaround is to either not use any directory in the pattern used for a FileHandler or use a directory which actually exists on the disk.

我认为这是因为有一个以上的记录器实例打开它或其他一些外部应用程序打开它带有读/写锁。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM