I am not sure what you meant by synchronization. Solution as per my understanding is as follows.
If you want to lock the file while a write is in progress,
you should be using nio.
try {
File file = new File("a.txt");
FileOutputStream fin = new FileOutputStream(file);
FileChannel fchannel = fin.getChannel();
fchannel.lock();
fin.write(250);
fchannel.force(false);
Thread.sleep(200000);
} catch(Exception e) {
e.printStackTrace();
}
If you run the above code and while it is sleeping, if you try to edit it and save(use textpad or notepad), it would not allow since it is locked by the Thread.
For more information, read through nio and nio.channel packages.