You shouldn't read and write to a file at the same time. In the best case, you'll end up with corrupted data, or an IO error.
If it's for inter-process communication, you should instead use sockets or higher-level systems like JMS.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…