dart:io library
The IO library is used for Dart server applications, which run on a stand-alone Dart VM from the command line. This library does not work in browser based applications.
This library allows you to work with files, directories, sockets, processes, HTTP servers and clients, and more.
Properties
const APPEND #
const APPEND = FileMode.APPEND
const ASCII #
const ASCII = Encoding.ASCII
dynamic set exitCode(int status) #
Global exit code for the Dart VM.
The exit code is global for the Dart VM and the last assignment to exitCode from any isolate determines the exit code of the Dart VM on normal termination.
set exitCode(int status) {
if (status is !int) {
throw new ArgumentError("setExitCode: int status expected");
}
_ProcessUtils._setExitCode(status);
}
const ISO_8859_1 #
const ISO_8859_1 = Encoding.ISO_8859_1
const READ #
const READ = FileMode.READ
final IOSink stderr #
IOSink get stderr {
if (_stderr == null) {
_stderr = _StdIOUtils._getStdioOutputStream(2);
}
return _stderr;
}
final Stream<List<int>> stdin #
Stream<List<int>> get stdin {
if (_stdin == null) {
_stdin = _StdIOUtils._getStdioInputStream();
}
return _stdin;
}
final IOSink stdout #
IOSink get stdout {
if (_stdout == null) {
_stdout = _StdIOUtils._getStdioOutputStream(1);
}
return _stdout;
}
const UTF_8 #
const UTF_8 = Encoding.UTF_8
const WRITE #
const WRITE = FileMode.WRITE
Functions
StdioType stdioType(object) #
StdioType stdioType(object) {
if (object is _StdStream) {
object = object._stream;
} else if (object is _StdSink) {
object = object._sink;
}
if (object is _FileStream) {
return StdioType.FILE;
}
if (object is Socket) {
switch (_StdIOUtils._socketType(object._nativeSocket)) {
case _STDIO_HANDLE_TYPE_TERMINAL: return StdioType.TERMINAL;
case _STDIO_HANDLE_TYPE_PIPE: return StdioType.PIPE;
case _STDIO_HANDLE_TYPE_FILE: return StdioType.FILE;
}
}
if (object is IOSink) {
try {
if (object._target is _FileStreamConsumer) {
return StdioType.FILE;
}
} catch (e) {
// Only the interface implemented, _sink not available.
}
}
return StdioType.OTHER;
}
void sleep(Duration duration) #
Sleep for the duration specified in duration.
Use this with care, as no asynchronous operations can be processed in a isolate while it is blocked in a sleep call.
void sleep(Duration duration) {
int milliseconds = duration.inMilliseconds;
if (milliseconds < 0) {
throw new ArgumentError("sleep: duration cannot be negative");
}
_ProcessUtils._sleep(milliseconds);
}
void exit(int status) #
Exit the Dart VM process immediately with the given status code.
This does not wait for any asynchronous operations to terminate. Using exit is therefore very likely to lose data.
void exit(int status) {
if (status is !int) {
throw new ArgumentError("exit: int status expected");
}
_ProcessUtils._exit(status);
}