static class · System.IO
File
public static class File
- Kind
- static class
- Namespace
- System.IO
- Assembly
- System.Core
- Access
- public, static, abstract
- Source file
IO.ant
Inheritance
- Base classes
-
AnyFile
Methods
ReadAllText(str path) : str
#
WriteAllText(str path, str text)
#
AppendAllText(str path, str text)
#
Delete(str path)
#
When the file was last written, in milliseconds since 1970 (UTC).
Private and internal members (6)
Inherited members (5)
GetTypemethod from AnyUndescribedmethod from AnyToStringmethod from AnyHashmethod from Anydestroymethod from Any
Source
File as Antril, decompiled from its Larva HIR.
// System.IO.File — System.Core (decompiled from Larva HIR)
import System;
import System.Text;
into namespace System.IO
{
public static class File
{
extern("file.read") ReadInto(u16[] path) : i64;
extern("file.take") TakeInto(u8[] bytes);
extern("file.write") WriteFrom(u16[] path, u8[] bytes, i64 append) : i64;
extern("file.kind") KindOf(u16[] path) : i64;
extern("file.delete") DeleteAt(u16[] path) : i64;
extern("file.time") TimeOf(u16[] path) : i64;
public:
Exists(str path) : bool => KindOf(Unicode.ToUtf16(path)) == 1;
ReadAllBytes(str path) : u8[]
{
i64 size = ReadInto(Unicode.ToUtf16(path));
if (size < 0)
throw new IOError("cannot read " + path);
u8[] bytes = new u8[(i32)size];
TakeInto(bytes);
return bytes;
}
ReadAllText(str path) : str => Encoding.UTF8.GetString(ReadAllBytes(path));
ReadAllLines(str path) : List<str> => ReadAllText(path).Lines();
WriteAllBytes(str path, u8[] bytes)
{
if (WriteFrom(Unicode.ToUtf16(path), bytes, 0) != 0)
throw new IOError("cannot write " + path);
}
WriteAllText(str path, str text)
{
WriteAllBytes(path, Encoding.UTF8.GetBytes(text));
}
AppendAllText(str path, str text)
{
if (WriteFrom(Unicode.ToUtf16(path), Encoding.UTF8.GetBytes(text), 1) != 0)
throw new IOError("cannot write " + path);
}
WriteAllLines(str path, List<str> lines)
{
StringBuilder text = new StringBuilder();
{
ListIterator<str> _iterator1 = lines.Iterator();
loop (_iterator1.Next())
{
str line = _iterator1.Current;
text.AppendLine(line);
}
}
WriteAllText(path, text.ToString());
}
Delete(str path)
{
if (DeleteAt(Unicode.ToUtf16(path)) != 0 && KindOf(Unicode.ToUtf16(path)) != 0)
throw new IOError("cannot delete " + path);
}
/// When the file was last written, in milliseconds since 1970 (UTC).
GetLastWriteTime(str path) : i64
{
i64 time = TimeOf(Unicode.ToUtf16(path));
if (time < 0)
throw new IOError("no file " + path);
return time;
}
}
}