Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 6th, 2006, 01:47 AM
Registered User
 
Join Date: May 2006
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old October 6th, 2006, 04:23 AM
Registered User
 
Join Date: Oct 2006
Location: , , .
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.

Reply With Quote
  #3 (permalink)  
Old October 6th, 2006, 01:25 PM
Registered User
 
Join Date: May 2006
Location: , , .
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



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
could any one explain this code for me ? method Access VBA 1 August 13th, 2005 03: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 10: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 05:05 PM



All times are GMT -4. The time now is 05:42 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.