Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Sybex 816, Appendix B, page 688 errata

 
Greenhorn
Posts: 10
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In answer to question 22 (Chapter 9: NIO.2) there is:

The APPEND option creates the file if it does not exist...


It refers to this code:

If the file does not exist, function newBufferedWriter will create it if:
  • no option at all is present (in this case method works as if the CREATE, TRUNCATE_EXISTING, and WRITE options are present; link to java docs)
  • option for creating is present (CREATE/CREATE_NEW)

  • Since StandardOpenOption.APPEND is already present, option for creating file must by written explicitly. Otherwise NoSuchFileException is thrown when file does not exist.
    Therefore option B is not correct and option C is correct.
     
    Marshal
    Posts: 79634
    380
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Didn't find that in the errata. You are correct; I also tried such code on JShell and failed to create the file.
     
    author & internet detective
    Posts: 41967
    911
    Eclipse IDE VI Editor Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Agreed. Added to errata
     
    reply
      Bookmark Topic Watch Topic
    • New Topic