FileHandle
Overview
Represents a random access file. FileHandle can be used to read from, write to, open, and close files.
Use case
You can use FileHandle when you need to get access to a file content, for example:
var LogFile := Folder.UserLocal.CreateFile("log.txt", false);
var Handle := LogFile.Open(FileOpenMode.ReadWrite);
try
Handle.Write([72, 101, 108, 108, 111]);
Handle.Seek(0, SeekOrigin.Begin);
writeLn(new Sugar.String(Handle.Read(5).ToArray));
finally
Handle.Close;
LogFile.Delete;
end;
Output:
Hello
Location
- Reference: Sugar
- Namespace: Sugar.IO
constructor
constructor(FileName: String; Mode: FileOpenMode)
FileHandle(String FileName, FileOpenMode Mode)
init(_ FileName: String, _ Mode: FileOpenMode)
FileHandle(String FileName, FileOpenMode Mode)
Sub New(FileName As String, Mode As FileOpenMode)
Parameters:
- FileName:
- Mode:
Close mapped
method Close
void Close()
func Close()
void Close()
Sub Close()
Flush mapped
method Flush
void Flush()
func Flush()
void Flush()
Sub Flush()
FromFile
class method FromFile(aFile: File; Mode: FileOpenMode): FileHandle
static FileHandle FromFile(File aFile, FileOpenMode Mode)
static func FromFile(_ aFile: File, _ Mode: FileOpenMode) -> FileHandle
static FileHandle FromFile(File aFile, FileOpenMode Mode)
Shared Function FromFile(aFile As File, Mode As FileOpenMode) As FileHandle
Parameters:
- aFile:
- Mode:
Length
property Length: Int64 read write;
Int64 Length { get; set; }
var Length: Int64 { get{} set{} }
Int64 Length { __get; __set; }
Property Length() As Int64
Position
property Position: Int64 read write;
Int64 Position { get; set; }
var Position: Int64 { get{} set{} }
Int64 Position { __get; __set; }
Property Position() As Int64
Parameters:
- Count:
Parameters:
- Buffer:
- Count:
Parameters:
- Buffer:
- Offset:
- Count:
Seek mapped
method Seek(Offset: Int64; Origin: SeekOrigin)
void Seek(Int64 Offset, SeekOrigin Origin)
func Seek(_ Offset: Int64, _ Origin: SeekOrigin)
void Seek(Int64 Offset, SeekOrigin Origin)
Sub Seek(Offset As Int64, Origin As SeekOrigin)
Parameters:
- Offset:
- Origin:
Write (array of Byte) mapped
method Write(Buffer: array of Byte)
void Write(Byte[] Buffer)
func Write(_ Buffer: Byte...)
void Write(Byte[] Buffer)
Sub Write(Buffer As Byte())
Parameters:
- Buffer:
Write (Binary) mapped
method Write(Data: Binary)
void Write(Binary Data)
func Write(_ Data: Binary)
void Write(Binary Data)
Sub Write(Data As Binary)
Parameters:
- Data:
Parameters:
- Buffer:
- Count:
Parameters:
- Buffer:
- Offset:
- Count:
Length
property Length: Int64 read write;
Int64 Length { get; set; }
var Length: Int64 { get{} set{} }
Int64 Length { __get; __set; }
Property Length() As Int64
Position
FromFile
class method FromFile(aFile: File; Mode: FileOpenMode): FileHandle
static FileHandle FromFile(File aFile, FileOpenMode Mode)
static func FromFile(_ aFile: File, _ Mode: FileOpenMode) -> FileHandle
static FileHandle FromFile(File aFile, FileOpenMode Mode)
Shared Function FromFile(aFile As File, Mode As FileOpenMode) As FileHandle
Parameters:
- aFile:
- Mode:
constructor
constructor(FileName: String; Mode: FileOpenMode)
FileHandle(String FileName, FileOpenMode Mode)
init(_ FileName: String, _ Mode: FileOpenMode)
FileHandle(String FileName, FileOpenMode Mode)
Sub New(FileName As String, Mode As FileOpenMode)
Parameters:
- FileName:
- Mode:
Close mapped
method Close
void Close()
func Close()
void Close()
Sub Close()
Flush mapped
method Flush
void Flush()
func Flush()
void Flush()
Sub Flush()
Parameters:
- Count:
Parameters:
- Buffer:
- Count:
Parameters:
- Buffer:
- Offset:
- Count:
Seek mapped
method Seek(Offset: Int64; Origin: SeekOrigin)
void Seek(Int64 Offset, SeekOrigin Origin)
func Seek(_ Offset: Int64, _ Origin: SeekOrigin)
void Seek(Int64 Offset, SeekOrigin Origin)
Sub Seek(Offset As Int64, Origin As SeekOrigin)
Parameters:
- Offset:
- Origin:
Write (array of Byte) mapped
method Write(Buffer: array of Byte)
void Write(Byte[] Buffer)
func Write(_ Buffer: Byte...)
void Write(Byte[] Buffer)
Sub Write(Buffer As Byte())
Parameters:
- Buffer:
Write (Binary) mapped
method Write(Data: Binary)
void Write(Binary Data)
func Write(_ Data: Binary)
void Write(Binary Data)
Sub Write(Data As Binary)
Parameters:
- Data:
Parameters:
- Buffer:
- Count:
Parameters:
- Buffer:
- Offset:
- Count: