Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics 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 October 6th, 2006, 12:47 AM
Registered User
 
Join Date: May 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can someone explain this code to me


Hi,

//I am initializinng the URL object
URL addr = new URL("http://sfbay.craigslist.org/rid/");

//Opening a bufferedinputstream object
BufferedInputStream bin = new BufferedInputStream(addr.openStream());

//Initialize a Stringbuffer
StringBuffer bfr = new StringBuffer();

//Declare a byte array
byte[] b = new byte[1024];

???????? I dont understand what these following two lines do
for (int n; (n = bin.read(b)) != -1;) {
bfr.append(new String(b, 0, n));

//This returns the string value the StringBuffer
bfr.toString()

Can someone explain this.

Thanks,
pandu

 
Old October 6th, 2006, 03:23 AM
Registered User
 
Join Date: Oct 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It judges if the StringBuffer bfr is not empty,it'll read data from URL and append it to the StringBuffer.

 
Old October 6th, 2006, 12:25 PM
Registered User
 
Join Date: May 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey, Thanks, I understood that, my question is
why is
byte[] b = new byte[1024];

because byte[] b = new byte[1]; was also working ,

and what does this do new String(b, 0, n)

Thanks,
pandu








Similar Threads
Thread Thread Starter Forum Replies Last Post
could any one explain this code for me ? method Access VBA 1 August 13th, 2005 02:02 AM
Explain some code on p178 jgrasso BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 June 3rd, 2005 09:51 PM
explain please rein Javascript 3 January 31st, 2005 09:47 AM
Please explain this code : p131 top para ababb BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 January 28th, 2005 06:02 PM
Could somebody explain this to me, please? czambran BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 June 7th, 2004 04:05 PM





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