Forums Register Login

problem in canRead and canWrite

+Pie Number of slices to send: Send
I have two programs.

FileWriterUtil.java
-write data into local txt file
FileReaderUtilNew.java
- read the data from the above same txt file.

While FileWriterUtil is writing, FileReaderUtilNew has to wait till that writing process completely written.

i am cheking the above scenario(whether completely written or not) by using canRead and canWrite methods. But both methods are giving output as "true" while FileWriterUtil is writing


System.out.println("can Read value--->"+fname.canRead()); "true"
System.out.println("can write value"+fname.canWrite()); "true"

if(fname.canRead()){

br = new BufferedReader(new FileReader(fname));
String a= br.readLine();
}else{
System.out.println("Other Process writing into this file..please wait..");
}



Please advice me why it so.?how can i come to know whether writing process completely finished or not ?
+Pie Number of slices to send: Send
If you open a file in write mode you can also read from it. What you need to do is check for canWrite() in FileReaderUtilNew.java. Only one process can hold the write handle.
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1005 times.
Similar Threads
File permission
File object creation
Program to check whehter a file is read-only / write
Ensuring that a file is not currently being written to
Pulling up File Permissions using Java API ???
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 02:31:36.