| fopen |
(String path, String mode [, Dictionary init]) |
yoix.stdio |
| fopen |
(String path, String mode [, String key, Object value, ...]) |
|
| |
Returns a stream that references the local file named by
path
and allows the operations selected by
mode,
which should be one of:
"r" |
open for reading
| "w" |
create or truncate for writing
| "a" |
append; open for writing at the end of file, or create for writing
| "r+" |
open for update, which allows reading and writing
| "w+" |
truncate or create for update
|
fopen
returns
NULL
if the open failed.
The optional arguments can be used to initialize fields in the stream that
fopen
returns that are not explicitly set by
fopen.
They can be collected together in a
Dictionary
and supplied as the
init
argument, or they can be supplied as two or more arguments, organized in pairs,
with the first element being a
String
that names the field and the second element being the value that should be
assigned to that field.
Streams opened with
fopen
can be closed with
fclose
or
close.
Even though the interpreter tries to close streams that are open
but no longer accessible, it is not a foolproof implementation,
so an explicit close when you are done with an open stream is
the best policy.
| |
| Example: |
On a UNIX-like system the program,
import yoix.stdio.*;
String line[1024];
File file;
if ((file = fopen("/etc/passwd", "r")) != NULL) {
while (fgets(line, 1024, file) != NULL)
fputs(line, stdout);
fclose(file);
}
copies the system password file to standard output.
| | |
| Return: |
File
| | |
| See Also: |
access,
close,
fclose,
fflush,
freopen,
open,
reopen,
stat,
unlink
|
|
Yoix is a registered trademark of AT&T Inc.
|