Stream Support
Basic operation
- open(fileName, [ "r" or "w" ] )
|
open() creates FileInputStream or FileOutputStream, depending on the
2nd parameter, from the specified file name.
If the 2nd parameter is not specified "r" is implicitly passed.
- read(inputStream)
- read(inputStream, outputStream)
- read(reader)
- read(reader, writer)
|
read() reads from inputStream (or reader) and
writes to outputStream (or writer).
When the second parameter is omitted the default output stream is used.
import("java.io.*")
function copyFile (src, dst){
fin = open(src, "r")
fout = open(dst, "w")
read(fin, fout)
fin.close()
fout.close()
}
|
URL
- readURL(urlString)
- readURL(urlString, outputStream)
|
readURL() reads a document from urlString and write it to
outputStream.
When the second parameter is omitted the default output stream is used.
setProperty("proxyHost", "machine")
setProperty("proxyPort", "8080")
readURL("http://java.sun.com/")
|
Serialization
- writeObject(object, filename)
- readObject(filename)
|
writeObject() serializes object and save in filename.
readObject() reads serialized data from filename.
Reading Resources
e.g.
rsrc = getResource("/init.pnut")
read(rsrc.openStream())
|