• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sequence of proper wrapping selection(File I/O doubt)

 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good evening,
Being that printWriters can wrap around BufferedWriters and BufferedWriters can wrap around a PrintWriters, In the exam iF there is a Dnd where I have to place these how do know which to wrap around which?
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Amitabha Batranab

I think you confused because of the term Wrap . Well let me explain.
The PrintWriter has these constructors

PrintWriter(File f) (as of Java 5)
PrintWriter(String filePath)(as of Java 5)
PrintWriter(OutputStream os)
PrintWriter(Writer writer)


so when you want to work with the PrintWriter atleast you need any one of the objects (File ,String ,OutputStream ,Writer )

As you know the Writer and OutputStream are abstract classes they can be instantiated through their concrete sub -classes only.

coming to your doubt in which order you need to use these . Lets take an example to write a String in the File through Writer. you can use the any of the following

1) creating File Object pointing to existing File , Passed to the
PrintWriter (new Fashion in java 5)

2) create String with the valid path of the File Passed to the
PrintWriter (new Fashion in java 5)

3) create a FileOutputStream pointing to the File , passed to the
PrintWriter (old fashion )

4) create a type of writer may be a BufferdWriter which again need a FileWriter . Create the both and passed to the PrintWriter constructor.

hope i'm clear to you . This we are calling as a decorator pattern used in Java you can see more details about this in

Head First Design Patterns - Kathy Sierra (More cleared Explanation)

Decorator Pattern
[ September 05, 2006: Message edited by: Arul Prasad ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic