String, text, numbers, I/O II part
but it didn t seem to work
Answer:
URL url = new URL("http://www.java.sun.com");
BufferedReader in;
in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine())!=null){
   // process str
}
you can use this to retrieve a html file.
Cheng Tao
 Q: I am wondering if JDK supports to open a file in the exclusive mode?
Answer: No, file locking is not supported in current VMs. You can implement
lockfiles, however, using the File.createNewFile() method. Since JDK 1.3: 
"Atomically creates a new, empty file named by this abstract pathname if and only if
a file with this name does not yet exist. The check for the   existence of the file and
the creation of the file if it does not exist are a single operation that is atomic with
respect to all other filesystem activities that might affect the file. This method, in
combination with the deleteOnExit() method, can therefore serve as the basis for a
simple but reliable cooperative file locking protocol."
 Q: How do I write an image to stdout? This is for a cgi program that will return an
image to a browser.
For example, if a user click on a link to 
http://somewhere.edu/cgi/getpix.cgi
 the
browser will receive image data from the cgi program and will display the image.
Answer: Send "Content type: image/gif"   and then send the data.
Alternatively, send an HTML page, with a pointer to the (possibly freshly written)
image on the server.
   
Tim Tyler Try my latest game   it rockz   http://rockz.co.uk/
 Q: Does anyone know how I can get around the fact that a Message obj (from
the JavaMail API) is not serializable?
I would like to save a message obj to the hd, then read the file (is  file  the wrong
word here?) back to my e mail client and read it as a Message obj.
Answer: The obvious answer is: implement serializable yourself in a subclass!
But! That won t work. The serialization mechanism will throw an exception at runtime.
Even if it didn t, the class may be nonserializable for a good reason, for example it
might contain a socket, which can t be reinitialized from a stream.
What you need is a subclass that implements the Externalizable interface, and then
your own code that saves as serializable objects those attributes of the object that
you need to reconstitute it later. I m not familiar with this particular object, but I
imagine it has several get() methods that return serializable objects like Strings or
ints. What you have to do is recover those objects and put them into the output
stream yourself, and reverse the process on unserialization. The fields that are not
file:///F|/a_jsite/350_tips/stings_text__date_numbers_io II.htm (4 of 7) [2001 07 08 11:25:00]






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java web hosting

 

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved