About java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • marmor
    Registered User
    • May 2001
    • 3

    #1

    About java

    First of all, how can I open and read from a online file in Java, I've tried fopen and it doesn't seem to work...
    and maybe if u know of some good downloadable tutorials about java please let me know...

    10x, MarMor.
  • Lord Assmore
    Confirmed User
    • Mar 2001
    • 588

    #2
    The best way to do it is probably by first creating an URL object and then apply the method openStream to it. The call will return a stream object, from which you can read the contents of the URL.

    Example program that prints the yahoo.com root file to StdOut:

    <tt><pre>
    import java.net.*;
    import java.io.*;

    public class URLReader {
    public static void main(String[] args) throws Exception {
    URL yahoo = new URL("http://www.yahoo.com/");
    BufferedReader in = new BufferedReader(
    new InputStreamReader(
    yahoo.openStream()));

    String inputLine;

    while ((inputLine = in.readLine()) != null)
    System.out.println(inputLine);

    in.close();
    }
    }
    </pre></tt>

    Good (the best?) documentation can be found at http://java.sun.com/docs/?frontpage-javaplatform

    [This message has been edited by Lord Assmore (edited 05-20-2001).]

    Comment

    • marmor
      Registered User
      • May 2001
      • 3

      #3
      thanks man...
      by the way in some places, i go by the the nickname Lord MarMor... kinda close to your...

      Comment

      Working...