Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem in canRead and canWrite  RSS feed

 
saivenkat venkatesan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Purushoth Thambu
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!