[2418] in java-interest
Getting a text file with a URL
daemon@ATHENA.MIT.EDU (Brian Jepson)
Sun Oct 1 05:12:59 1995
Date: Sun, 1 Oct 1995 02:24:22 -0400 (EDT)
From: Brian Jepson <bjepson@conan.ids.net>
To: java-interest@java.sun.com
In-Reply-To: <199509290630.XAA08667@java.sun.com>
On Thu, 28 Sep 1995 Adam Krawitz <cs169060@cs.brown.edu> wrote:
>
> In the pre-beta API, is there a function that takes a URL for a text
> file as a parameter, and returns the contents of the file as a String?
> I'm thinking along the lines of Applet.getImage and
> Applet.getAudioClip, but for text.
>
> I've tried various combinations of URL, URLConnection, and InputStream
> objects without any luck so far. I thought there might be a straight
> forward method that I'm blindly overlooking.
>
Please keep in mind that I am a complete newbie to java, but here is a
sample program that reads the contents of a URL and prints it out (I
guess you could assign it to a string, as well):
import java.io.*;
import net.www.html.URL;
class visit {
public static void main(String args[]) {
int mychar;
URL MyUrl = new URL("http://localhost/test.txt");
InputStream is;
is = MyUrl.openStream();
while ((mychar = is.read()) != -1)
System.out.write(mychar);
}
}
Hope this helps,
Brian Jepson (bjepson@conan.ids.net)
Director of Advanced Technology, Prosoft Systems International, Inc.
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com