Does FileInputStream acquire lock

I am seeing weird behaviour:

1. fin = new FileInputStream(f);

if (null == (in = new InputStreamReader(fin))) {

return;

}

if (null != in) {

bData = null;

sData = null;

System.out.println(schname + " Currently Working on "

+ f.getAbsoluteFile());

if (null != in) {

br = new BufferedReader(in);

StringBuilder sBuildValidateData = new StringBuilder();

StringBuilder s = new StringBuilder();

while ((sData = br.readLine()) != null) // read data

{

}

}

2. Now after reading from BufferedReader if I try to rename file f using f.renameTo(); then it doesn't rename. And, also when I try to cut paste the file it tells me that it's being used by other program - which means it has a lock.

3. Now I try the same code on UNIX, and it just works fine.

Is it that windows implementation locks the file when it's being read ?

[940 byte] By [mohitanchliaa] at [2007-11-27 11:51:52]
# 1

yes, but it's Windows doing that, not the implementation of Java.

ejpa at 2007-7-29 18:40:56 > top of Java-index,Core,Core APIs...
# 2

But, isn't this controlled by java ? I am reading files within the java program so why is windows doing it ? I thought control over File locks is within JVM, is that not true ?

mohitanchliaa at 2007-7-29 18:40:56 > top of Java-index,Core,Core APIs...
# 3

Different locks. Windows always sets a file lock when you open a file. How can Java control that? Java provides locks for file regions.

ejpa at 2007-7-29 18:40:56 > top of Java-index,Core,Core APIs...