Reading an html file?

How would you go about opening a page such as http://www.google.com/ and then reading the source and passing this into a string or buffer of some sort?

import java.util.*;
import java.io.*;
import java.net.*;
public class Test
     public static void main(String[] a)
          Scanner in = new Scanner(System.in); //the command prompt inputstream
          System.out.print("Enter URL: ");
          String target = in.next(); //get the next string entered. A space is the delimiter so there can't be any spaces
          Scanner scan = null;
          try{
               scan = new Scanner(new URL(target).openStream()); //the site's inputstream
          }catch(Exception x){
               System.out.println("Error: site not found"); //if they didn't enter a valid URL do this
          while(scan.hasNextLine()) //while there is another line in the file
               System.out.println(scan.nextLine()); //print that line
}

Similar Messages

  • How to read an html file and replace a text using text_io

    hi,
    i want ro read an html file using text_io and replace a particular text with a new text
    eg: i want to replace a text called "data.js" and with "maps.js"
    how do i do this?

    You have to write your own code to do that. TEXT_IO is just a low level text file interface.
    You need to read in all the text, save it in some internal format (array of varchar2's maybe or in the DB) and then perform a search on the text you have read in, find out where the instances of "data.js" are located and substitute them with "maps.js" After that you need to write to a new file and delete the old one. There is no way to search and replace inside the existing file (what's sometimes referred to as 'in-place' substitution).
    See the help section called About the TEXT_IO package for an overview of how it works and some code examples.

  • Opening a browser to read an HTML file

    I need to be able to open a browser to read an html file that I can specify. The HTML file probably, but not necessarily, reside on the same machine as the app.
    I've looked through the APIs amd can't seem to figure this one out.
    Any help would be appreciated.

    Do you really need to open a browser, or are you just wanting to bring the text of an HTML doc into your program? If by some chance it's the latter, then that can be done pretty easily with URLConnection.getInputStream()...

  • Reading in HTML file then writing to file - losing formatting.

    I am reading in a HTML file using a Buffered Reader then writing it to a file. However when i write it to a file using
    out = new PrintWriter(new BufferedWriter(new FileWriter(path, true)));
    out.write(content);
    out.flush();
    i seem to lose all carriage returns and find that the whole html is on one single line with the only noticable formatting being the spaces between the html tags.
    How can i stop it losing carriage returns?

    You only showed the part where you are writing it out.
    Does your reader code look like this:
      BufferedReader r = ...
      String content = "";
      while (true) {
        String line = r.readLine();
        if (line == null) break;
        content += line;
      }If it does, the problem lies here, as doing a readLine removes the line terminator. Soooo....
        content += line + "\n";Of course, to be most efficient and good, don't use String concatenation, use a StringBuffer (though it should be noted that when I decompiled this test code, suns compiler did indeed use a StringBuffer).
    When you print, use the PrintWriter methods print and priintln as they don't throw exceptions.

  • ??? Is it Possible to Read an HTML file in PI !!! and check a word"Failure"

    Hi All,
    My requirement is to pick an HTML file and search for a word " Failure" If its present then i need to update a particular value if not then other value.
    Regards,
    Jude

    >>My requirement is to pick an HTML file
    can be done, if html is welformed xml.
    >>and search for a word " Failure"
    if you know which tag could contain the word "failure" then i think it is possible to search in graphical mapping.
    >>If its present then i need to update a particular value if not then other value.
    you said "particular value". Is it in the target message type, if yes, then you can decide.
    I am not sure, whether your requirement and the purpose of using PI for this go together.
    thanks
    BJagdishwar.

  • Cannot read the html files

    I cannot seem to make JavaHelp find my HTML files, although it has found my Map and XML files.
    The structure is as follows:
    - the XML files are in myclasspath/doc/onlinehelp
    - the HTML files are in myclasspath/doc/onlinehelp/html
    How should I reference them from my Map.jhm file?
    Have I forgottoen any enviroment variables?
    This is really urgent
    Thanks
    Bj?rn

    The entries in your map file should take the form
    <mapID target="target_string" url="html/filename.htm" />
    so that the url includes the relative path from the directory where the xml files are.

  • Reading HTML files in a java

    Hi guys,
    In a project that I have to submit, I have to read a HTML file's text and then have to check if it contains any word or words, that are present in a List.
    I already have the list, But how can I read the HTML file and then how can I compare it's text...
    any idea please...any kind of help is appreciated

    [http://forums.sun.com/thread.jspa?threadID=5115338&messageID=9394434]

  • To read HTML files

    Hi all,
    I have got the following coding. From this coding, i will read some HTML pages in a folder named Content. I will only need to read the HTML files and not any other files. How can i achieve this? Meaning what coding do i have to add in my coding to tell it to read the HTML files only.
    This is the coding i have:
    public class Copy
         public static void main(String[] args) throws IOException
              processDir(new File("../Content"));
         static void processDir(File path) throws IOException
              System.out.println("path " + path.getAbsolutePath());
              File[] files = path.listFiles();
              if(files == null)
              return;
              for (int a = 0; a < files.length; a++)
              if (files[a].isDirectory())
                   processDir(files[a]);
              else
                   BufferedReader in = new BufferedReader(new FileReader(files[a]));
         StringBuffer sb = new StringBuffer();
         String str;
         while ((str = in.readLine()) != null) {
         sb.append(str);
         in.close();
              //System.out.println(sb.toString());
    Hope you guys can help me.
    Thanks!
    Peifeng

    Groan go here http://sourceforge.net/projects/ambient/, get the package... Look at SystemFiles.CoreFiles.LoadAllIOContexts line 152, you will find your answer there....

  • How do we load a html file from a folder on a sdcard into a webview panel c# windows phone 8.1

    Every time a character is made in my app it is saved to an html file named after it in a folder called RpgApp on the sdcard
    so if the characters name is john smith then there will be a john-smith.htm located in RpgApp folder on the sdcard
    now that bit works great
    the app also makes a list of buttons each one named after a file inside the RpgApp folder (so in this case there would be a button named john-smith.html ) and the content is the same as the name so it displays as john-smith.html
    each button has the following method on click 
    private void htmlButtonClick(object sender, RoutedEventArgs e)
    StorageFolder externalDevices = Windows.Storage.KnownFolders.RemovableDevices;
    string curDir = externalDevices.ToString();
    Button button = sender as Button;
    Uri result = new Uri(String.Format("file:///{0}/RpgApp/"+button.Name,curDir));
    web.Navigate(result);
    now the idea is that when you click the button the webview control (aptly named "web") loads up the content of the file (you notice button.name as part of the url? well thats because the buttons name is the file name :) 
    but instead the browser remains unmoved, just sits thier blank
    to test i changed web.Navigate(result); to web.NavigateToString(button.Name);
    and sure enough when ever i clicked a button the webview displayed the name of the button i clicked
    any ideas?

    Hi D.Eastwick,
    I will recommand you read the html file content from the folder in the sd card and convert it to a string, after that we can use the
    NavigateToString method to load the html content in the WebView.
    Besides, please try to do a test by puting the html file in a
    LocalFolder and use the URL like this: "ms-appdata:///...." to see if it works.
    Best Regards,
    Amy Peng
    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.

  • Call .html file in ABAP report (se38)

    Hi,
    My question is, is it possible to call and execute an html file in a report?
    For example, you have 2 containers in the report, 1 is for the html part and the 2nd for some ALV table (which is not the problem in this discussion).
    The HTML part is a separate .html file on the server which works with a few .js files called in it.
    I've done some research but couldn't find anywhere how read the HTML file in a report, and to work just like it does in a browser.
    All I found was how to create a javascript from a report (only some simple examples like show a string..), or how to create an HTML file from a report and execute it in se38, but instead I need to know how to read an HTML in the report and place it in a container (which is a little more complex because of all the javascripts that it calls within).
    Can anybody help me with this?
    Thanks!

    I saw this program but I couldn't figure out where is this called from: document_url      = 'HTMLFrame1.htm' on line 100.
    To be more precise i need to call this HTML file which is on the server, and i need it to be executed in the container of the report, alongside with the javascript files it calls within:
    <!doctype html>
    <html>
    <head>
        <title>Essential Studio for JavaScript : Radial Gauge - Default</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8">
        <link href="bootstrap.min.css" rel="stylesheet">
        <link href="ej.widgets.all.min.css" rel="stylesheet" />
        <link href="default.css" rel="stylesheet" />
        <link href="default-responsive.css" rel="stylesheet" />
        <script src="jquery-1.10.2.min.js" type="text/javascript"></script>
        <script src="jquery.easing.1.3.min.js" type="text/javascript"></script>
        <script src="excanvas.min.js" type="text/javascript"></script>
        <script src="ej.web.all.min.js" type="text/javascript"></script>
        <script src="properties.js" type="text/javascript"></script>
    </head>
    <body>
        <div class="content-container-fluid">
            <div class="row">
                <div class="cols-sample-area" align="center">
                    <div id="circularframe">
                        <div id="CoreCircularGauge">TEXT
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script type="text/javascript">
            $(function () {
                $("#CoreCircularGauge").ejCircularGauge({
                    backgroundColor: "transparent", width: 500, load: "loadGaugeTheme",
                    scales: [{
                        showRanges: true,
                        startAngle: 122, sweepAngle: 296, radius: 130, showScaleBar: true, size: 1, maximum: 120, majorIntervalValue: 20, minorIntervalValue: 10,
                        border: {
                            width: 0.5,
                        pointers: [{
                            value: 100,
                            showBackNeedle: true,
                            backNeedleLength: 20,
                            length: 95,
                            width: 7,
                            pointerCap: { radius: 12 }
                        ticks: [{
                            type: "major",
                            distanceFromScale: 2,
                            height: 16,
                            width: 1, color: "#8c8c8c"
                        }, { type: "minor", height: 8, width: 1, distanceFromScale: 2, color: "#8c8c8c" }],
                        labels: [{
                            color: "#8c8c8c"
                        ranges: [{
                            distanceFromScale: -30,
                            startValue: 0,
                            endValue: 70
                            distanceFromScale: -30,
                            startValue: 70,
                            endValue: 110,
                            backgroundColor: "#fc0606",
                            border: { color: "#fc0606" }
                            distanceFromScale: -30,
                            startValue: 110,
                            endValue: 120,
                            backgroundColor: "#f5b43f",
                            border: { color: "#f5b43f" }
        </script>
    </body>
    </html>

  • How to include HTML file in JSP using HTML elements or Javascript?

    Hi,
    I have around 15000 static html files one for each item which we display each upon invoking an item.The HTML file should be part of a JSP file.
    Please note that the name of the HTML file is determined dynamically
    Placing all the HTML files within the web application does not give us good performance so i would like to put all of them in the webserver.
    I am not able to include the file in the JSP using the jsp:include attribute if i place the HTML files in the webserver ,
    in order to do that i think should use either HTML element or javascript to include the HTML in the JSP.is there any alternative to <Jsp:include>
    Does anyone have an idea how to include the HTML file and take advan tage of webserver?
    Any ideas are appreciated

    What you need to do is simply read the HTML file from the disk and dump it out to the outputstream. It really is that simple.
    There's no reason you need to include all 15000 files in the actual WAR, you can place those files any place handy that is easy for the application to see (in another directory, or accessible from a file server if you have multiple front ends).
    Then, just write a utiility function that takes the output stream (i.e. the 'out' JSP variable), and the file name, read the file, and write it to the stream.
    If you start noticing performance issues, then you can try doing some caching, but truth is your OS should be doing that for you.
    But, truth be told that's the only practical way to do it.
    Another solution would be to use JavaScriipt and XMLHttpRequest (i.e "AJAX") to load the file at the client side, and simply replace a tag with the results.
    That's also pretty trivial to write, any web site talking about AJAX should give you hint there.
    Of course, that won't work for folks who have JavaScript turned off, or some other incompatible browser, whereas the server side solution obviously works everywhere.

  • Modify colours of some links in html file

    Hi,
    Can anyone give me some idea how to go about reading a html file , identifying links and changing the colours of these links thru a java program ?
    Thanks

    adadfsdff

  • Parsing html files via an url

    Hi,
    I already have a Java program that is able to read in html files that are stored on my computers hard drive. Now I would like to expand its functionality by being able to parse html files straight from the web.
    For example, when the program is run, I would like to be able to give it an url for a given website. Then, I would like to be able to parse the html file that the link goes to.
    I've searched the forum, but have not been able to find anything of any real use. If you could offer an overview or point me towards a resource, I would be very greatful.

    If you've done things right, you have a HTML reader/parser that takes an InputStream. For Files, this would be a FileInputStream.
    For URLs, this would be the InputStream you get from URLConnection.getInputStream(). You can get a URLConnection by calling openConnection() on a URL instance (created from your input url of course).

  • How to use Swing html to parse a html file..

    I am currently working on a project in java.i need to read a Html file, extract the table tag along with its contents if it has a button embedded in it and replace it with another code..
    i tried it with Reg Ex in java but in vain.. Any help is great... I need an idea of how to use Html parser for this prob.. any examples will be fine..

    Run the program from command line, this way you will see the errors, if any.
    example.: java -jar theJarfile.jar
    I was successful in creating a comm application. I placed the win32com.dll in the same directory of my application jar file and all worked.
    I also extracted the comm.jar , and jar'd my app with the extracted comm files to make one jar.
    I also had a fileWriter() to get the clients jre path and my app would write the javax.properties file to the correct place.
    It took me severel weeks and late nights to accomplish this, but it was all necessary to be able to install only my app, and not a bunch of api's that were needed.

  • How to read data from a excel and HTML file

    Hi
        I am writing an 2D-array of string into Excel/HTML file using Report generation.
        Can anybody tell me how to retrieve back the written data from the same files again and view in array format.
    Thanks & regards
    Visuman 
    Solved!
    Go to Solution.

    you can use activex to read the data from the excel fileback in the array format...go through this vi...may b this will help you.........
    Attachments:
    Read Excel-1.vi ‏32 KB

Maybe you are looking for

  • Text Entry Interaction -- Password Processing

    Hi everyone, I have this text entry interaction set up to show asterisks when user types the password. I was wondering if it can be done in a way where I have 3 fields: field 1 asking the user to enter current password. field 2 asking the user to ent

  • How to custom table field to be sortable at core form

    Hi, Can anyone provide the hint for the captioned topic. Example, R11i PO autocreate document form, column 'Requestor' is not sortable, how to custom it to be sortable? Thanks in advance. Rgds, CY

  • Database upgrade from 8i to 10g using exp/imp

    Dear Friends, Please provide the steps to upgrade from 8i to 10g using exp/imp. Thanks, Rathinavel

  • Safari won't load pages

    I'm running 4.0.5 and off and on over the last few months it would just stop loading pages. I have it open up to the thumbnail view of the top sites and whether I would click on one of those or click on a site in the bookmark bar, it just shows it th

  • Elapsed Time [New]

    Hi can anyone help me on this please...... Comments and suggestions are welcomed.  Regards, NKR Solved! Go to Solution.