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


 

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

Read (Int32): Binary  mapped

 

method Read(Count: Int32): Binary

 

Binary Read(Int32 Count)

 

func Read(_ Count: Int32) -> Binary

 

Binary Read(Int32 Count)

 

Function Read(Count As Int32) As Binary

Parameters:

  • Count:

Read (array of Byte, Int32): Int32  mapped

 

method Read(Buffer: array of Byte; Count: Int32): Int32

 

Int32 Read(Byte[] Buffer, Int32 Count)

 

func Read(_ Buffer: Byte..., _ Count: Int32) -> Int32

 

Int32 Read(Byte[] Buffer, Int32 Count)

 

Function Read(Buffer As Byte(), Count As Int32) As Int32

Parameters:

  • Buffer:
  • Count:

Read (array of Byte, Int32, Int32): Int32  mapped

 

method Read(Buffer: array of Byte; Offset: Int32; Count: Int32): Int32

 

Int32 Read(Byte[] Buffer, Int32 Offset, Int32 Count)

 

func Read(_ Buffer: Byte..., _ Offset: Int32, _ Count: Int32) -> Int32

 

Int32 Read(Byte[] Buffer, Int32 Offset, Int32 Count)

 

Function Read(Buffer As Byte(), Offset As Int32, Count As Int32) As Int32

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:

Write (array of Byte, Int32)  mapped

 

method Write(Buffer: array of Byte; Count: Int32)

 

void Write(Byte[] Buffer, Int32 Count)

 

func Write(_ Buffer: Byte..., _ Count: Int32)

 

void Write(Byte[] Buffer, Int32 Count)

 

Sub Write(Buffer As Byte(), Count As Int32)

Parameters:

  • Buffer:
  • Count:

Write (array of Byte, Int32, Int32)  mapped

 

method Write(Buffer: array of Byte; Offset: Int32; Count: Int32)

 

void Write(Byte[] Buffer, Int32 Offset, Int32 Count)

 

func Write(_ Buffer: Byte..., _ Offset: Int32, _ Count: Int32)

 

void Write(Byte[] Buffer, Int32 Offset, Int32 Count)

 

Sub Write(Buffer As Byte(), Offset As Int32, Count As Int32)

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

 

property Position: Int64 read write;

 

Int64 Position { get; set; }

 

var Position: Int64 { get{} set{} }

 

Int64 Position { __get; __set; }

 

Property Position() As Int64

 

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()

Read (Int32): Binary  mapped

 

method Read(Count: Int32): Binary

 

Binary Read(Int32 Count)

 

func Read(_ Count: Int32) -> Binary

 

Binary Read(Int32 Count)

 

Function Read(Count As Int32) As Binary

Parameters:

  • Count:

Read (array of Byte, Int32): Int32  mapped

 

method Read(Buffer: array of Byte; Count: Int32): Int32

 

Int32 Read(Byte[] Buffer, Int32 Count)

 

func Read(_ Buffer: Byte..., _ Count: Int32) -> Int32

 

Int32 Read(Byte[] Buffer, Int32 Count)

 

Function Read(Buffer As Byte(), Count As Int32) As Int32

Parameters:

  • Buffer:
  • Count:

Read (array of Byte, Int32, Int32): Int32  mapped

 

method Read(Buffer: array of Byte; Offset: Int32; Count: Int32): Int32

 

Int32 Read(Byte[] Buffer, Int32 Offset, Int32 Count)

 

func Read(_ Buffer: Byte..., _ Offset: Int32, _ Count: Int32) -> Int32

 

Int32 Read(Byte[] Buffer, Int32 Offset, Int32 Count)

 

Function Read(Buffer As Byte(), Offset As Int32, Count As Int32) As Int32

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:

Write (array of Byte, Int32)  mapped

 

method Write(Buffer: array of Byte; Count: Int32)

 

void Write(Byte[] Buffer, Int32 Count)

 

func Write(_ Buffer: Byte..., _ Count: Int32)

 

void Write(Byte[] Buffer, Int32 Count)

 

Sub Write(Buffer As Byte(), Count As Int32)

Parameters:

  • Buffer:
  • Count:

Write (array of Byte, Int32, Int32)  mapped

 

method Write(Buffer: array of Byte; Offset: Int32; Count: Int32)

 

void Write(Byte[] Buffer, Int32 Offset, Int32 Count)

 

func Write(_ Buffer: Byte..., _ Offset: Int32, _ Count: Int32)

 

void Write(Byte[] Buffer, Int32 Offset, Int32 Count)

 

Sub Write(Buffer As Byte(), Offset As Int32, Count As Int32)

Parameters:

  • Buffer:
  • Offset:
  • Count: