Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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: 75634
    354
    • 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: 41073
    848
    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
     
    An elephant? An actual elephant. Into the apartment. How is the floor still here. Hold this tiny ad:
    Free, earth friendly heat - from the CodeRanch trailboss
    https://www.kickstarter.com/projects/paulwheaton/free-heat
    reply
      Bookmark Topic Watch Topic
    • New Topic