How to read a web page as an ascii file

I need to open an url and read the contents, as it
were a simple local ascii file. This give me just
garbage, as [B@fd2e84b (that change every time,
seems to be a memory address, not the contents..).
<pre>
import java.io.*;
import java.net.*;
try {
URL j_urlobj = new URL("http://www.google.com";);
URLConnection j_urlcon = j_urlobj.openConnection();
BufferedInputStream j_bis =
   (BufferedInputStream)j_urlcon.getInputStream();
byte[] j_data = new byte[4096];
int j_size;
j_size = j_bis.read(j_data, 0, 4096);
while (j_size != -1) {
out.print(j_data);
j_size = j_bis.read(j_data, 0, 4096);
j_bis.close();
} catch (Exception e) { out.print(e.toString()); }
</pre>
What is wrong?? Thank you!
Stefano

I try your code and it's work right with a little change....
The problem is that you read bytes, so if you want something readable try to convert to a String.
String s = new String(j_data)
out.println(s);
Here, the complete code:
try {
URL j_urlobj = new URL("http://www.google.com");
URLConnection j_urlcon = j_urlobj.openConnection();
BufferedInputStream j_bis =
new BufferedInputStream(j_urlcon.getInputStream());
byte[] j_data = new byte[4096];
int j_size;
j_size = j_bis.read(j_data, 0, 4096);
while (j_size != -1) {
out.print(new String(j_data));
j_size = j_bis.read(j_data, 0, 4096);
j_bis.close();
} catch (Exception e) { out.print(e.toString()); }

Similar Messages

  • How to download a web page intact as one file, which can be easily done with Safari

    On Safari all I do with a complex web page is 'Save As (whatever I wish, or its existing description. That shows as a complete webpage in a single file. Firefox saves it as a file PLUS a folder of elements. Takes up twice my desktop real estate, and makes going back too complex. Chrome has a sort of fix which now only works occasionally. Am probably overlooking some kind of Ad-on, but have yet to find it. Any thoughts?

    Safari saves the web pages in the ''web archive'' format. Basically, it rolls every element of the web page into a single file. It provides the convenience of having everything in a single file but it may not necessarily mean that it saves space. Note that this format is not very portable - other browsers like Internet Explorer cannot open this web archive file.
    <BR><BR> Since Firefox saves the web page and its associated elements separately, it can be opened in any other browser. To allow saving web pages in web archive format from Firefox, you can try this add-on: [https://addons.mozilla.org/en-US/firefox/addon/mozilla-archive-format/ Mozilla Archive Format].

  • How to read a web page using https ?

    Hi,
    I'm trying to read a page under a HTTPS connection. I got a certificate from my server and I'm not behind a firewall.
    I find everthing confusing here, and the Java Secure Socket Extension Reference Guide from Sun is not helping too much.
    If anyone could post some simple sample code to from the absolute 0, read the full page it would be really, really appreciated. It must include all the steps (from setting the trustStore pointing to the certificate, to actually reading the page).
    And yes, I know this is really dummy, but I'm new to the connection part of the Java API and time is really short to solve this.
    Thanks in advance,
    - Juan

    Amacfal,
    First of, thank you for your help. But I'm trying to read a page using a HTTPS connection, and the code below (very similar to mine) doesn't work. At some point you must state where you got the PFX file. Where and how, I don't know.
    Regards,
    - Juan
    Here is some sample code:
    private void getWebPage(String searchPageURL)
    //Local Attributes
    String readString;
    URL url;
    URLConnection urlConnection;
    BufferedReader HTMLpage;
    try
    //Connecting to URL
    url = new URL(searchPageURL);  //e.g.
    /e.g. searchPageURL = "http://www.yahoo.com"
    urlConnection = url.openConnection();
    HTMLpage = new BufferedReader(new
    r(new InputStreamReader(url.openStream()));
    //Looping through Web Page
    while((readString = HTMLpage.readLine()) !=
    )) != null)
    System.out.println(readString);
    catch (Exception e)
    e.printStackTrace();
    // NEED TO MANAGE ERRORS + LOG FILE
    }You will need to import the following:import java.net.*;
    import java.io.*;

  • HT4972 How can I zoom the web page only vertically or horizontally ,i.e.,wThen I want to read the web page can I enlarge the page so that the font only increases size ?

    How can I zoom the web page only vertically or horizontally ,i.e.,wThen I want to read the web page can I enlarge the page so that the font only increases size ?

    You can't.  (Fonts increase in size like everything else, not in height alone).

  • How to open a web page in JFrame.

    Please let me know how to open a web page in the Java Frame.

    HTML code can be viewed in any Swing component you want.

  • Adobe air how do links between web pages

    Hello!
    I try to use adobe air with dreamweaver : The tutorial shows how to package a web page but I can not integrate multiple pages. The html code <a href="page2.html"> test link </ a> is incorrect? Should I add something in the xml file?
    Thanks for help.

    It's just basic page for test :
    <html>
    <head>
    <title>AIRHelloWorld</title>
    <script>
    function init()
    runtime.trace("init function called");
    </script>
    </head>
    <body onload="init()">
    <div align="center">Hello World</div>
    <div><a href="page2.html">test de lien</a></div>
    </body>
    </html>

  • How to prevent duplicate web pages from loading

    <blockquote>Locking duplicate thread.<br>
    Please continue here: [[/questions/930219]]</blockquote>
    how to prevent duplicate web pages from loading

    <s>Hi berternie, can you describe this in more detail?
    Are you saying the identical page loads in two different tabs? When does that happen -- when you click a link? or when you use a bookmark?
    Or do you have multiple tabs open every time you see your home page (i.e., when you start up, open a new window, or click the home icon)?</s>
    I see, you have more info in this thread: https://support.mozilla.org/en-US/questions/930219

  • How tall is a web page?

    So we're doing pages 900+ pixels wide these days, but I'm wondering how much vertical content we can use before the user has to start scrolling - what he/she first sees when the page loads. Is there a rule of thumb (or mouse finger) for this?

    It's true that you need to make an educated guess about the people who will be viewing the site.
    For instance, if you know for a (relative) fact that they all use 12 inch monitors and IE6, that gives you an idea of what to shoot for.
    If you have a sense that they all have wraparound monitors (surely someone will invent them) that are 36 inches on the diagonal and the latest, greatest Browsers, that tells you something else.
    You can get general statistics about Monitor usage from w3c http://www.w3schools.com/browsers/browsers_display.asp Allowing for a vertical scrollbar and top of the Monitor screen material (toolbars, etc.), you can kind of guess at the actual Viewport sizes.
    If you want to keep people on your page, and not scrolling to kingdom come (how tall is a web page? how high is the sky?), there are strategies:
    Make the header stable and the container below it scrollable within a container so it looks like it's all on the screen...
    Make the page short
    Make the page liquid, so it doesn't hang off the page on small monitors or cower in the corner of larger monitors
    Use Spry Tabbed Panels, or Spry Accordions, or other Spry content techniques
    You can imitate Browser/Monitor Viewport sizes by doing Window > Cascade and adjusting the size of the floating window manually (drag the right bottom corner). The size of the Viewport will show at the right side of the Tag Selector at the bottom of the Document Window (1038 x 628, for instance).
    Beth

  • How to include non web pages to the "Create PDF from Web Page" feature?

    In Acrobat Pro (v. 10), when I use the "Create PDF from Web Page" feature, it works great for html pages, but it skips non-html links (doc, pdf, ppt, xls, etc). I need Acrobat Pro to convert those files and put them in the order as well. I don't see an option for this in settings. Is there ANY way I can do this? This is for an archiving purpose and I have 10,000 plus files to convert. Please help.

    This is a question i'm trying to answer too. My issue is that I have a PDF file which itself contains links to both DOC and PDF files. The end result is that I need one consolidated PDF containing all the linked files (in order).
    I can run the "create from web page" on this PDF file, and it'll download them, but not convert them. It just adds them as "jumbled" text to the end of the document. I need it to download, convert, and then append them.
    So, as isunshine3 asked above, any way to have Adobe convert the files that it finds linked when running the "create from web page"?
    THanks
    Matt

  • How do I save a web page as a .txt file?

    There is no 'save as'; there is no menu bar. The limited menu bar in the lower left of the phone does not cover this.

    AFAIK then the Firefox mobile version only allows to save web pages as a PDF file, so you won't be able to do this.
    *https://support.mozilla.org/kb/get-started-firefox-android
    *https://support.mozilla.org/kb/firefox-android-faq
    *https://support.mozilla.org/kb/firefox-mobile-android-tutorials

  • When exporting files to web pages Aperture keeping losing files, so for instance, if I choose to export 600 images to a new web page, it might do 524 images but not the full 600. I've tried resetting Aperture, it's the latest version etc etc. Help please!

    If anyone can help me with this I would be seriously grateful.
    When exporting mutliple files to web pages Aperture keeping losing files, so for instance, if I choose to export 600 images to a new web page, it might make 524 pages but not the full 600. I've tried resetting Aperture and its persmission and am using the latest version of 3.
    I have 3600 images which I need to upload as sublfolders, each with their own URL and at the moment Aperture is dropping of anything from 1 to 90 images.
    This is critical as people need to see each and every on of these images online. So if a file has 600 photos in it, Aperture should make a URL with 600 full image pages. And this is what it's not doing. On small files, say 30 or so it seems to work well, it's when it gets to more than that the problem starts.
    I've used Aperture in the past under previous versions and not had this problem.
    Any help would be great.
    Thanks.
    Bob.

    Hi Jack,
    Thanks for responding (as it seems as though no one else has been able to provide any insight as of yet)! Not sure if you saw my recent post, but the version of Aperture on the 2008 MacBook has been upgraded to 3.1.2 (not sure how; I bought it in 2009, but only have OS X 10.5.8... which apparently can't house 3.1.2 of Aperture, but hey, like many other anomalies i'm encountering, I'm no longer surprised!). I am unable to upgrade it any further, as it warns me that my OS X does not fit the requirements. I exported the projects as libraries; however, like I posted before, apparently these are from too old of a version for the new Aperture (3.3.1) to handle and import.
    It's getting to the point where I'd almost pay to upgrade the OS X on my previous MacBook (10.5.8) to something newer in order to THEN update Aperture to a newer version; however, my previous MacBook simply cannot handle this (the specs are awful -- hence my decision to save up and upgrade to the newest MBP with Retina).
    I've spent hours upon hours transferring files, libraries as projects, previews, versions, even masters (though, apparently some of them aren't accessible?) with no luck. I've rebuilt the library and reprocessed everything. And this is all after having to return one MBP already since Aperture 3.3.1 is glitch-y as it is, and froze everything for having a "managed library". So, now that I know that I have to deal with a referenced library in Aperture... I just need to actually transfer my previous library to my new one (hopefully WITH adjustments since these are years worth of photos and work).
    Again, any help is appreciated. I've lost enough sleep, time, and vision health over this at this point.
    Also, I know Migration Assistant is an option, I was told that it wouldn't work properly anyway because of the different operating systems, and the potential for problems.

  • How do i scan multiple pages into one pdf file

    How do I scan multiple pages into one pdf file?

    That depends on your scanning software. Adobe Reader doesn't scan.

  • How to read and update the value of property file

    Hi,
    I am not able read the values from property file.
    Please tell me how to read and update the values from property file using Properties class
    This is my property file : - Config.properties its located in D:\newfolder
    Values
    SMTP = localhost
    Now i need to change the value of the SMTP
    New value :
    SMTP =10.60.1.9
    Pls Help me
    Thanks
    Merlin Rosina,

    Post a small (<1 page) example program that forum members can copy and run that demonstrates your problem.

  • RE: How can I create a page break in a file?

    Thank you, Glen. I tried WriteText. But it didn't work.
    Tien Wang
    Indus Consultancy Services
    [email protected]
    From: Glen A. Whitbeck
    Sent: Thursday, September 11, 1997 11:59 AM
    To: Wang, Tien
    Cc: forte-users; owner-forte-users
    Subject: Re: How can I create a page break in a file?
    Instead of using "WriteLine," try using "WriteText" ("WriteLine" writes
    TextData into an open file, while "WriteText" writes data to a stream)
    like this:
    <method 1>
    myFile : file = new();
    myFile.WriteText('\f');
    Glen
    Wang, Tien wrote:
    Hi,
    I am creating a text file for a report which contains multiple pages.
    How can I create a page break in my file? I tried to use the
    following
    two methods, but neither of them works. Specifically, it seems a
    special
    character printed in the file. But when I print the file through a
    WordPad, it didn't separate pages.
    I am currently using version 3.0.C on Windows NT 4.0 with a HP Plus 4
    printer. Any help will be greatly appreciated.
    Tien Wang
    Indus Consultancy Services
    [email protected]
    >
    <method 1>
    myFile : file = new();
    file.writeLine('\f'); --- \f is the form feed in the C language
    <method 2>
    myFile : file = new();
    j : IntegerData = new( value = 14 );
    c : char = j.IntegerValue; -- c now contains ascii 14 (form feed)
    p : pointer to char = &c; -- Set a pointer to the character
    pageBreakTxt : TextData = new();
    pageBreakTxt.Concat(p);
    myfile.writeLine(pageBreakTxt);

    Tien,
    Try myFile.WriteText('\x0c'); instead of myFile.WriteText('\f');
    Regards
    Richard Stobart
    -----Original Message-----
    From: Wang, Tien [SMTP:[email protected]]
    Sent: Friday, September 12, 1997 6:09 PM
    To: Glen A. Whitbeck
    Cc: forte-users; owner-forte-users
    Subject: RE: How can I create a page break in a file?
    Thank you, Glen. I tried WriteText. But it didn't work.
    Tien Wang
    Indus Consultancy Services
    [email protected]
    From: Glen A. Whitbeck
    Sent: Thursday, September 11, 1997 11:59 AM
    To: Wang, Tien
    Cc: forte-users; owner-forte-users
    Subject: Re: How can I create a page break in a file?
    Instead of using "WriteLine," try using "WriteText" ("WriteLine" writes
    TextData into an open file, while "WriteText" writes data to a stream)
    like this:
    <method 1>
    myFile : file = new();
    myFile.WriteText('\f');
    Glen
    Wang, Tien wrote:
    Hi,
    I am creating a text file for a report which contains multiple pages.
    How can I create a page break in my file? I tried to use the
    following
    two methods, but neither of them works. Specifically, it seems a
    special
    character printed in the file. But when I print the file through a
    WordPad, it didn't separate pages.
    I am currently using version 3.0.C on Windows NT 4.0 with a HP Plus 4
    printer. Any help will be greatly appreciated.
    Tien Wang
    Indus Consultancy Services
    [email protected]
    >
    <method 1>
    myFile : file = new();
    file.writeLine('\f'); --- \f is the form feed in the C language
    <method 2>
    myFile : file = new();
    j : IntegerData = new( value = 14 );
    c : char = j.IntegerValue; -- c now contains ascii 14 (form feed)
    p : pointer to char = &c; -- Set a pointer to the character
    pageBreakTxt : TextData = new();
    pageBreakTxt.Concat(p);
    myfile.writeLine(pageBreakTxt);

  • How can I create a page break in a file?

    Hi,
    I am creating a text file for a report which contains multiple pages.
    How can I create a page break in my file? I tried to use the following
    two methods, but neither of them works. Specifically, it seems a special
    character printed in the file. But when I print the file through a
    WordPad, it didn't separate pages.
    I am currently using version 3.0.C on Windows NT 4.0 with a HP Plus 4
    printer. Any help will be greatly appreciated.
    Tien Wang
    Indus Consultancy Services
    [email protected]
    <method 1>
    myFile : file = new();
    file.writeLine('\f'); --- \f is the form feed in the C language
    <method 2>
    myFile : file = new();
    j : IntegerData = new( value = 14 );
    c : char = j.IntegerValue; -- c now contains ascii 14 (form feed)
    p : pointer to char = &c; -- Set a pointer to the character
    pageBreakTxt : TextData = new();
    pageBreakTxt.Concat(p);
    myfile.writeLine(pageBreakTxt);
    -----------------------------------

    Tien,
    Try myFile.WriteText('\x0c'); instead of myFile.WriteText('\f');
    Regards
    Richard Stobart
    -----Original Message-----
    From: Wang, Tien [SMTP:[email protected]]
    Sent: Friday, September 12, 1997 6:09 PM
    To: Glen A. Whitbeck
    Cc: forte-users; owner-forte-users
    Subject: RE: How can I create a page break in a file?
    Thank you, Glen. I tried WriteText. But it didn't work.
    Tien Wang
    Indus Consultancy Services
    [email protected]
    From: Glen A. Whitbeck
    Sent: Thursday, September 11, 1997 11:59 AM
    To: Wang, Tien
    Cc: forte-users; owner-forte-users
    Subject: Re: How can I create a page break in a file?
    Instead of using "WriteLine," try using "WriteText" ("WriteLine" writes
    TextData into an open file, while "WriteText" writes data to a stream)
    like this:
    <method 1>
    myFile : file = new();
    myFile.WriteText('\f');
    Glen
    Wang, Tien wrote:
    Hi,
    I am creating a text file for a report which contains multiple pages.
    How can I create a page break in my file? I tried to use the
    following
    two methods, but neither of them works. Specifically, it seems a
    special
    character printed in the file. But when I print the file through a
    WordPad, it didn't separate pages.
    I am currently using version 3.0.C on Windows NT 4.0 with a HP Plus 4
    printer. Any help will be greatly appreciated.
    Tien Wang
    Indus Consultancy Services
    [email protected]
    >
    <method 1>
    myFile : file = new();
    file.writeLine('\f'); --- \f is the form feed in the C language
    <method 2>
    myFile : file = new();
    j : IntegerData = new( value = 14 );
    c : char = j.IntegerValue; -- c now contains ascii 14 (form feed)
    p : pointer to char = &c; -- Set a pointer to the character
    pageBreakTxt : TextData = new();
    pageBreakTxt.Concat(p);
    myfile.writeLine(pageBreakTxt);

Maybe you are looking for

  • Open Purchase Orders not considered as requirement for MRP Run

    Hi , We are facing a issue of Open Purchase orders not appeared in Stock requirements list and also it is not considered as requirement for MRP Run against reservation. As aresult for a reservation demand of 10 units we are ending with Open POs 10 un

  • Integration multiple R/3 systems with APO via CIF

    Hello all, the idea is to connect via CIF over 20 R/3 system on several releases with one APO system. I can find a lot of documentation and success stories with one ERP and one APO system, but no one with more than one ERP system. Has anybody experie

  • Will a 3 hour long download of an upgrade be cancelled if the Mac goes to sleep mode during the download process?

    I have a Mac 10.10.1 27 in. monitor 2009 late Memory 4GB 1067 MHz DDR3 To download the above OS upgrade (10.1.1), because I noticed the long time needed to download, I clicked on system preferences, Energy saver, Computer sleep/never, Display sleep/1

  • ISight to run in MSN (Windows Vista Business via Parallels)

    Hi guys ! I'm a MAC newbee and as I need to run some Windows applications I have installed Windows Vista Business via Parallels. Everything works just fine - except for the iSight web-cam when running MSN. I have installed the AppleiSight drivers fro

  • Question about Stacking

    Hello Everyone, I have a quick question about stackwise plus technology. I would like to confirm that there is no redundancy at the ethernet switch port in terms of a physical problem. The reason I ask is that we are deploying stacked switches shortl