Resin 1.1
FAQ
Reference
JavaDoc
Demo
Java Tutorial
Getting Started
Configuration
Topics
JSP
XTP/XSL
JavaScript
JS Library
Core Library
File Library
Servlet Library
Database Library
XML Library
VFS
File
ReadStream
WriteStream
InputStream
OutputStream
Files
The File object provides path and filesystem support: opening and removing files, listing directories, and retrieving file attributes. Paths are always URLs, using '/' to separate path components. Resin takes care of translating URLs into their system specific file names.
File Object
File(href) | Returns a new file object.
File instance properties
lookup(href) | Returns a new file object.
scheme | Returns the scheme of the file.
host | Returns the host of the file.
port | Returns the port of the file.
path | Returns the path of the file.
exists() | Returns true if the file refers to a file, directory or other object in the filesystem.
contentType | Contains the mime-type of the object. Filesystems which are not mime-aware return 'application/octet-stream'.
isDirectory() | Returns true if the file refers to a directory.
isFile() | Returns true if the file refers to a file, i.e. something which can be read by a stream.
length | Returns the length of the file in bytes.
lastModified | Returns the last modified time of the file.
canRead() | Tests if this file can be read.
canWrite() | Tests if this file can be written to.
list() | The contents of this directory or null if the file does not refer to a directory.
iterator() | Returns an iterator (jdk1.2 collection) of the contents of the directory.
mkdir() | Creates the directory named by the file. The parent directory must exist.
mkdirs() | Creates the directory named by the file and any parent directories if necessary.
remove() | Removes the directory or file named by the file.
renameTo(newFile) | Renames the file or directory to the new file. The parameter may either be a file object or a string.
createRoot() | Creates a restricted File object.
openRead() | Opens a stream for reading.
openWrite() | Opens a stream for writing.
openAppend() | Opens a stream for writing.
openReadWrite() | Opens a stream for reading and writing.
writeln(str [, str, ...]) | Convenience function writes the string to the file.
File Object | Resin 1.0
### File(href)
Returns a new file object. The href is any URL. href uses forward slashes to separate directories, even on non-unix operating systems.
File("test.xml")
| The file test.xml relative to the current working directory.
File("/home/ferg/foo.xml")
| A file in the user's home directory.
File("..")
| The parent of the current directory.
File("http://www.caucho.com")
| The Caucho Technology home page.
File("mailto:user@localhost")
| Preparing to mail to a user.
File("stderr:")
| The equivalent of Java's System.err user.

File instance properties | Resin 1.0

### lookup(href)

Returns a new file object. href is a path relative to the file.

File("foo").lookup("bar")
| File("foo/bar")
File("http://www.caucho.com").lookup("about.html")
| File("http://www.caucho.com/about.html")

### scheme

Returns the scheme of the file.

File("http://www.caucho.com").scheme
http

### host

Returns the host of the file. If the scheme does not support hosts, e.g. file:, it will return null.

File("http://www.caucho.com").host
www.caucho.com

### port

Returns the port of the file. If the scheme does not support ports, e.g. file:, it will return 0.

File("http://www.caucho.com:8080").port
8080

### path

Returns the path of the file.

File("http://www.caucho.com/foo/bar.html").path
/foo/bar.html

### exists()

Returns true if the file refers to a file, directory or other object in the filesystem.

### contentType

Contains the mime-type of the object. Filesystems which are not mime-aware return 'application/octet-stream'.

### isDirectory()

Returns true if the file refers to a directory.

### isFile()

Returns true if the file refers to a file, i.e. something which can be read by a stream.

### length

Returns the length of the file in bytes. Returns 0 for non-files.

### lastModified

Returns the last modified time of the file. According to the JDK, this may not correspond to system clock time.

### canRead()

Tests if this file can be read.

### canWrite()

Tests if this file can be written to.

Logging code can use this to write to a log only when enabled:

var log = File("log:/caucho/test") if (log.canWrite()) log.println("logging")

### list()

The contents of this directory or null if the file does not refer to a directory.

### iterator()

Returns an iterator (jdk1.2 collection) of the contents of the directory.

The following example writes the filenames of the current working directory.

for (var file in File) { writeln(file); }

### mkdir()

Creates the directory named by the file. The parent directory must exist.

### mkdirs()

Creates the directory named by the file and any parent directories if necessary.

The following example creates a temp directory

File("/tmp/caucho/jsp").mkdirs()

### remove()

Removes the directory or file named by the file.

The following example removes all files in the current directory.

for (var file in File) File(file).remove()

### renameTo(newFile)

Renames the file or directory to the new file. The parameter may either be a file object or a string.

### createRoot()

Creates a restricted File object. The restricted File only has access to children of the new root object. An absolute path will refer to the created root, not the root of the parent filesystem.

The following JSP example is safe, even though it returns a file given a query string. Normally, that's a big security mistake.

<%@ language=javascript %><% response.contentType = "text/plain"; // create virtual root var root = File.createRoot(); // write the file in the queryString out.writeFile(root(request.queryString)) %>

### openRead()

Opens a stream for reading.

### openWrite()

Opens a stream for writing.

### openAppend()

Opens a stream for writing.

### openReadWrite()

Opens a stream for reading and writing.

Streams open for read/write have all the methods of both read streams and write streams In addition, they ensure that writes are flushed before reads.

var s = File("tcp://localhost:80").openReadWrite(); s.writeln("GET /index.html") while (line = s.readln()) { writeln(line); }
<html><body> Welcome to our home page. </body></html>

### writeln(str [, str, ...])

Convenience function writes the string to the file.

The following example sends a mail message containing the single line "subscribe".

File("mailto:user@localhost").writeln("subscribe");

VFS |  | ReadStream

Copyright © 1998-2000 Caucho Technology. All rights reserved.
Last modified: Mon, 03 Apr 2000 11:20:13 -0700 (PDT)