open() creates FileInputStream or FileOutputStream, depending on the 2nd parameter mode, from the specified file name. If the 2nd parameter is not specified "r" is implicitly passed.
When "w" or "a" is given, the directory in which the specified file is included is made if it does not exist.
|
read() reads from input (or reader) and writes to outputStream (or writer). When the second parameter is omitted the output stream of the executing context is used.
import("java.io.*") function copyFile (src, dst){ fin = open(src, "r") fout = open(dst, "w") read(fin, fout) fin.close() fout.close() }
|
openURL() opens a stream of a URL document.
setProperty("proxyHost", "machine") // proxy setProperty("proxyPort", "8080") stream = openURL("http://java.sun.com/index.html") read(stream)
|
readURL("jar:http//javacenter.sun.co.jp/pnuts/applet.jar!/init.pnut")
|
e.g.
rsrc = getResource("/init.pnut") read(rsrc.openStream())
See also this for more detail on resources.
|
reader() creates a BufferedReader from the specified InputStream object. When encoding is specified, the Reader object is constructed with the encoding.
writer() creates a BufferedWriter from the specified OutputStream object. When encoding is specified, the Writer object is constructed with the encoding.
e.g.
rd = reader(open("large.txt")) while ((line = rd.readLine()) != null){ println(line) }
|
openByteArray() creates a ByteArrayOutputStream.
openCharArray() creates a CharArrayWriter.
e.g.
buf = openByteArray() read(open("foo.txt"), buf) buf.toByteArray() read(open("bar.txt"), buf) buf.writeTo(fd = open("baz.txt", "w")) fd.close()
|
getByteArray() reads data from inputStream and returns a byte array.
getCharArray() reads data from reader and returns a char array.
|
func is a function with two arguments; inputStream and outputStream. When in is specified, it is passed as the first parameter of func on a separate thread. For the second paramter of func, internally used PipedOuputStream is passed. Then pipe() returns a PipedInputStream object that is connected to the PipedOutputStream.
When out is specified, it is passed as the second parameter of func on a separate thread. For the first parameter of func, internally used PipedInputStream is passed. pipe() returns a PipedOutputStream that is connected to the PipedInputStream.
e.g.
pin = pipe(base64encode, open("test.dat")) read(pin, pout = pipe(gzip, open("test.gz", "w"))) pout.close()
|
writeObject() serializes object and save in a file or the specified output stream.
|
readObject() reads serialized data from a file or an input stream.