Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Beginning Java 2, JDK 5 Edition
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning Java 2, JDK 5 Edition
This is the forum to discuss the Wrox book Ivor Horton's Beginning Java 2, JDK 5 Edition by Ivor Horton; ISBN: 9780764568749
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Java 2, JDK 5 Edition section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 27th, 2006, 10:46 AM
Registered User
 
Join Date: Apr 2006
Location: beijing, , China.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default about charBuf.position() and Formatter

 String[] phrases = {"Rome wasn't burned in a day.",
                                               "It's a bold mouse that sits in the cat's ear.",
                                               "An ounce of practice is worth a pound of instruction."
                                             };

       // Create byte buffer to hold data to be written
       ByteBuffer buf = ByteBuffer.allocate(1024);

       System.out.printf("position = %2d Limit = %4d capacity = %4d%n",
                                                         buf.position(), buf.limit(), buf.capacity());

       // Create a view buffer
       CharBuffer charBuf = buf.asCharBuffer();
       System.out.println("Char view buffer:");
       System.out.printf("position = %2d Limit = %4d capacity = %4d%n",
                                                       charBuf.position(),charBuf.limit(),charBuf.capacit y());
       Formatter formatter = new Formatter(charBuf);

       // Write to the view buffer using a formatter
       int number = 0; // Proverb number
       for(String phrase : phrases) {
       //befor i run the follow statement charBuf.position() is 0 ,after run this sentence charBuf.position() value is 42,i want to know how the answer 42 is come,how to 42 is calculate?
           formatter.format("%nProverb%3d: %s", ++number, phrase);

in this book its file name is UsingAFormatter.java at part 10 about write file.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting formatter to org.apache.juli.FileHandler aurelije Apache Tomcat 1 January 12th, 2011 06:54 AM
How to get the position of an element nazran Javascript How-To 3 February 2nd, 2010 06:56 AM
Position barski XSLT 5 July 11th, 2007 01:54 PM
string formatter = "{0,22} {1}"; //what it mean? fukchai2000 C# 1 January 6th, 2006 08:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.