• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

problem in canRead and canWrite

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic