Know how make best and faster this?. View my code.

//ANYTHING KNOW HOW READ A HTML PAGE FROM
//A URLCONNECTION BEST AND FASTER THAN
//MY METHOD getHTMLFile(URL)?
// MY METHOD
public String getHTMLFile(URL ff)
char bufferc[]; // To put the content of the file
InputStream entrada=null;
try {                 
URLConnection conn=ff.openConnection();
entrada=conn.getInputStream();
BufferedReader leefichero=new BufferedReader(new InputStreamReader(entrada));
DataInputStream in=new DataInputStream(entrada);
String cadenafinal="";
// Who is the long of html file?
char c=' ';
filelength=0;
try {
while(true)
c=(char)(in.readByte());
filelength++;
cadenafinal=cadenafinal+c;
catch(java.io.EOFException IOEOF) {}
// put the content of the file in char's buffer.
bufferc=new char[(int)filelength];
cadenafinal.getChars(0,filelength,bufferc,0);
catch(IOException IOE)
System.err.println("Error: "+IOE);
return "Error, m�todo getHTMLFile(URL).";
// Return the content of the file in a type String.
if(echo) System.out.println(new String(bufferc));
return (new String(bufferc));
} // End of method getHTMLFile(URL).

i had an error in the code. which comes from working too fast. & also for free!
so you should cast to char after you do a check for -1. that is the only change.
two other issues:
you can use a larger buffer size for expected larger streams.
you really should be closing your own stream within a finally clause.
import java.io.*;
import java.net.*;
class Test2 {
     public static String getHTML(URL ff) throws IOException {
          BufferedInputStream data = null;
          try {
               data = new BufferedInputStream( ff.openStream() ) ;
//               data = new BufferedInputStream( ff.openStream(), 2048 or anything here ) ;
               StringBuffer buffer = new StringBuffer();
               int c; //not char c
               while ( -1 != ( c = data.read() ) )   //dont cast here
                    buffer.append( (char) c); //cast to char here
               return buffer.toString();
          } finally {
               try {
                    data.close();
               } catch (Exception e) { ;}//report or ignore
     public static void main(String[] args) throws IOException {
          try {
               String junk = Test2.getHTML( new URL(args[0]) );
               System.out.println(junk);
          } catch (IOException e) {
               e.printStackTrace();
     }

Similar Messages

  • I accidently deleted Safari and now I can't reinstall because it keeps telling me there is a newer version on my computer.  The issue is my system does not support the newer version.  Does anyone know how I can get around this?

    I accidently deleted Safari and now I can't reinstall because it keeps telling me there is a newer version on my computer.  The issue is my system does not support the newer version.  Does anyone know how I can get around this?

    Apple wanted to charge me 50 bucks jsut to talk to someone! 
    I believe you may be referring to the $49 ASL agreement at AppleCare? That is only when/if you are out of AppleCare Protection.
    Can you get to an AppleStore Genius Bar?
    They may be able to fix this for you. No charge.
    I highly doubt that. There is a $70 charge for troubleshooing software issues, EVEN IF there is AppleCare Warranty on the hardware.
    However, since there is no charge for an appointment at a Bar, go make one, and see what options they give you. Let us know how it goes.

  • How to create a special view for sharepoint list A and deploy this view to specific user personal view?

    How to create a public view for sharepoint list A and deploy this view to specific user personal view? Is that possible OOTB?

    Views cannot be exported or moved. Can you elaborate your requirement?
    --Cheers

  • My 6th generation nano isn't recognized by my computer. When I plug it in an error message pops up, which says "USB Device Not Recognized". Does anyone know how to start trouble shooting this. I updated both windows and iTunes.

    My 6th generation nano isn't recognized by my computer. When I plug it in an error message pops up, which says "USB Device Not Recognized". Does anyone know how to start trouble shooting this? I updated both windows and iTunes.

    Work through all the suggestions in this Apple support document first.
    iPod: Does not appear in Windows or iTunes and Device Manager is empty
    B-rock

  • I am selling my apple mac pro but do not know how to deregister and register it to the new owner; how do you do this?

    I am selling my apple mac pro but do not know how to deregister and register it to the new owner; how do you do this?

    Before you sell or give away your computer, in addition to the steps mentioned in this support article, take these steps:
    Run Apple Diagnostics or the Apple Hardware Test. The buyer will do this (or he should), and you don't want to be surprised by the results.
    Reset the PRAM and the SMC, which might contain personal information.
    If you set a firmware password, remove it by running Firmware Password Utility in Recovery mode.
    If you activated FileVault in OS X 10.7 or later, turn it off.
    If you use Boot Camp, the partition must be deleted
    If you created any other data partitions on the internal drive, remove them in Disk Utility.
    Erase the data partition(s) with the option to zero out data. An SSD doesn't need to be zeroed.
    You can't legally or practically transfer any software downloaded from the Mac App Store to the new owner of the machine, even if it was free. That includes OS X, so if you upgraded to OS X 10.7 or later, you must reinstall  an older OS, either from the installation media, if applicable, or by booting into Internet Recovery (option-command-R at the startup chime.) If you installed from physical media, deliver those to the new owner.
    If you're selling the machine, or donating it in working order, and it originally shipped with OS X 10.4 or 10.5, then you have the option of installing either from the discs that came with it or from a retail Snow Leopard disc (which you must then transfer with the machine.) The buyer should understand that if he doesn't get the original discs from you, he won't get the bundled iLife applications or the Apple Hardware Test. Replacements for the original discs can be ordered from Apple.
    The new owner will have to redownload any software that came from the App Store, including OS X upgrades, under his or her Apple ID. If you ever updated the bundled iLife applications (Garage Band, iMovie, and iPhoto) through the App Store, you can't transfer those either.
    Remove the machine from your list of registered products. If it's still covered by an AppleCare Protection Plan, transfer the coverage to the new owner by following the instructions in the AppleCare Terms and Conditions (under the heading "Transfer of Plan.")

  • HT1918 I changed the card and i want to know how make to change the data from itunes. I tried and doesn't work.

    I changed the card and i want to know how make to change the data from itunes. I tried and doesn't work. Please, Help Me!

    No. That's not what I said. You can get an out of warranty replacement, which will be exactly the same model, color, and will be locked in exactly the same way the original is. If you want an iPhone 5, get the 4S replaced, sell it, and use the money to put toward a new phone.

  • HT4009 Apple charged me £20.99 for in-app purchase for an app I just bought an hour ago while I did not bought any in-app purchase. How could I make claim and refund this money?

    Apple charged me £20.99 for in-app purchase for an app I just bought an hour ago while I did not bought any in-app purchase. How could I make claim and refund this money?

    If you didn't make an in-app purchase within the app then you can try contacting iTunes support via this page : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption
    You may also want to turn off in-app purchases via Settings > General > Restrictions > In-App Purchases 'off'

  • HT1212 My device is disabled and I can't open/unlock it to trust the computer so I need to know how do I get around this problem please.

    My device is disabled and I can't open/unlock it to trust the computer so I need to know how do I get around this problem please. I don't mind restoring it updating anything that will work

    Follow the instructions in the support document that you linked to the forum with. See the section about not syncing. You will probably need to erase it in iCloud to be able to restore it as new. Remove the device from your iCloud account which will disable Find My iPhone.

  • I just turned on iTunes on my Mac and suddenly instead of the usual song list there's a window with what looks like a screensaver graphic.  Anyone know how to get rid of this permanently?  Thanks.

    I just turned on iTunes on my Mac and suddenly instead of the usual song list there's a window with what looks like a screensaver graphic.  Everytime I close it it just comes back.  Does anyone know how to get rid of this permanently?  Thanks.

    See this thread...
    tt2

  • Include or create a view in the database and use this view?

    Well, I need to get related data of the main table from another related tables, so one way to do that is to use the Include method in Entity Framework to get this related data.
    However, I am thinking in another option, create a view in the database and use this view in entity framework. In this way, I avoid the needed of the include, because I think that is expensive in resources. But I am no very sure about that.
    I would like to know if the use of views on entity framework is a good idea to improve the performace or is better to use the include.
    For example, if I use the include I have the advantage that I get only one the main record and all the related data I have in the navigation properties, so the info is more shorted.
    Which is the advanteges and disadvantages of both methods to get related data in entity framework?
    Thank so much.

    Hello ComptonAlvaro,
    >>I would like to know if the use of views on entity framework is a good idea to improve the performace or is better to use the include.
    If your view would use a Join syntax to query master-child relationship tables, it actually is similar with the Include() method which actually results a duplicate records from master table, you could check this
    link for detail description.
    >>Which is the advanteges and disadvantages of both methods to get related data in entity framework?
    One visible difference is that records from Views are not editable by default(if you want edit them, you could refer to this
    blog).
    In your case, my suggestion that you could use the lazying load which will load the matter table once and disable the trace if you only need to display data.
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Could you let me know how to enable and use ITS on SAP ECC5  and ECC6

    Could you let me know how to enable and use ITS on SAP ECC5  and ECC6

    Hello Tina,
    please see here
    in tree select "Installation and Activation"
    <a href="http://help.sap.com/saphelp_nw70/helpdata/en/4f/2e6a52c3cdc44d83169b181a9c62ba/frameset.htm">http://help.sap.com/saphelp_nw70/helpdata/en/4f/2e6a52c3cdc44d83169b181a9c62ba/frameset.htm</a>
    <a href="http://help.sap.com/saphelp_nw70/helpdata/en/b8/2a8d65be7eee4eb66067f8a33d1c8b/frameset.htm">http://help.sap.com/saphelp_nw70/helpdata/en/b8/2a8d65be7eee4eb66067f8a33d1c8b/frameset.htm</a>
    best regards

  • Hello guys..does anybody know how to install and use adobe master collection with the new lion?   I need to use Flash and illustratore, but apparently those programmes are incompatible with the new operative sistem...   I am a new mac users and I'd like t

    Hello guys..does anybody know how to install and use adobe master collection with the new lion?
    I need to use Flash and illustratore, but apparently those programmes are incompatible with the new operative sistem...
    I am a new mac users and I'd like to know if there are other similar programmes I can use with lion!

    Lab79 wrote:
    Are you on Apple's payroll?
    well dude I can only let you know that as I work with those programme I don't have to pay for it is my company that pays the programme I whant to use( that's why I was asking if there where other programmes ..that I could use with lion insted that Illustrator and Flash!)..I know Adobe since 2005 and I can say that Adobs products are very good...I think that if it's an Adobe probleme or fault ..they will solve it very soon...but unfortunally I have the impression that after Jobs passed away Appel decided to change politics..and everything started to go very bad! (see FCP X)..
    good luck with apple dude..
    Where is the Apple problem? I have CS4 and CS5 running perfectly fine on my Macbook Pro. Installed 5 after Lion upgrade. Worth every cent. Adobe did have some catching up to do with Lion but with the CS5.5 update all runs fine. But not yours. So it is a problem with the Lion OS? You say you have been with Adobe since 2005. So you would be aware of all the other issues that Adobe had catching up with past Oss in Mac and Windows then. They get it right, but it is up to them. It is not up to Apple, nor Microsoft for that matter, to run around and check that every software developer in the world is running their business properly.
    And what has politics got to do with anything. Some people just have to blame Software for their poor Hardware maintainence of failure of the same.
    <The only think I can really do is to go back on my old windows...give back this orrible lap top and ask for my money back!>
    Great suggestion. You should go with that one, but good luck getting a refund.
    Bye

  • Pls. let me know how to get rid off this ribbon?

    Hello
    I am developing an VISITOR Adobe Interactive Form, i have Designer 8.1 and Reader 9.0 in my Windows 7 Laptop. When i checked the menu EDIT-->form properties --> Compatability, its Adobe XML form File (XDP) When i opened this VISITOR interactive form in a browser, right clicking and checked form
    PROPERTIES, then i saw the "PDF Version: 1.6 (Acrobat 7.x)"
    When i executed/run this interactive form, am getting a violet colred ribbon on the top of the form, with a text of "Pls fill out the folowing form. You can save data typed into this form" on left corner "
    But, i do not want to get/display/see this violet ribbon on my form, pls. let me know how t get rid off this robbon?

    I bet if you Google "iPhone error code 1611" you'll get a clue as to how to fix your problem

  • When I open my image, it is covered with tiny coloured dots.  how do I turn off this view?

    when I open my image, it is covered with tiny coloured dots.  how do I turn off this view? i've used photoshop for years and never encountered this.  i looked at the histogram for some means of turning it off, but no luck.  help

    The issue I think is connected to the colour profile, and the 8,16, or 32 bit image mode option.  In the past, my images have come from lightroom as 16 bit files and I've never had any issues.  I guess I'm not very adept at the file handling aspect of this program.  I shoot in RAW and like to play around with my photos, then print them.  I was under the impression I should be using the srgb colour selection not RGB, but then I've read I should change it to RBG once I'm ready to save the file to print.  I also changed my files over the 8 bit from 16 once I saved the after using photoshop.

  • There is suddenly a gray shelf under the app icons in dock. does anyone know how to get rid of this?

    there is suddenly a gray shelf under the app icons in dock. does anyone know how to get rid of this?

    Take a look at the various suggestions in 'More like this'  >>>>>>>> to the right of your original post.   And don't forget the links within the threads.   Several people have had that problem.

Maybe you are looking for