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)

Parameters:

  • FileName:
  • Mode:

Close  mapped

 

method Close

 

void Close()

 

func Close()

 

void Close()

Flush  mapped

 

method Flush

 

void Flush()

 

func Flush()

 

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

Parameters:

  • aFile:
  • Mode:

Length

 

property Length: Int64 read write;

 

Int64 Length { get; set; }

 

var Length: Int64 { get{} set{} }

 

Int64 Length { __get; __set; }

Position

 

property Position: Int64 read write;

 

Int64 Position { get; set; }

 

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

 

Int64 Position { __get; __set; }

Read (Int32): Binary  mapped

 

method Read(Count: Int32): Binary

 

Binary Read(Int32 Count)

 

func Read(_ Count: Int32) -> Binary

 

Binary Read(Int32 Count)

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)

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)

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)

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)

Parameters:

  • Buffer:

Write (Binary)  mapped

 

method Write(Data: Binary)

 

void Write(Binary Data)

 

func Write(_ Data: Binary)

 

void Write(Binary Data)

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)

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)

Parameters:

  • Buffer:
  • Offset:
  • Count:

 

Length

 

property Length: Int64 read write;

 

Int64 Length { get; set; }

 

var Length: Int64 { get{} set{} }

 

Int64 Length { __get; __set; }

Position

 

property Position: Int64 read write;

 

Int64 Position { get; set; }

 

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

 

Int64 Position { __get; __set; }

 

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)

Parameters:

  • aFile:
  • Mode:

 

constructor

 

constructor(FileName: String; Mode: FileOpenMode)

 

FileHandle(String FileName, FileOpenMode Mode)

 

init(_ FileName: String, _ Mode: FileOpenMode)

 

FileHandle(String FileName, FileOpenMode Mode)

Parameters:

  • FileName:
  • Mode:

Close  mapped

 

method Close

 

void Close()

 

func Close()

 

void Close()

Flush  mapped

 

method Flush

 

void Flush()

 

func Flush()

 

void Flush()

Read (Int32): Binary  mapped

 

method Read(Count: Int32): Binary

 

Binary Read(Int32 Count)

 

func Read(_ Count: Int32) -> Binary

 

Binary Read(Int32 Count)

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)

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)

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)

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)

Parameters:

  • Buffer:

Write (Binary)  mapped

 

method Write(Data: Binary)

 

void Write(Binary Data)

 

func Write(_ Data: Binary)

 

void Write(Binary Data)

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)

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)

Parameters:

  • Buffer:
  • Offset:
  • Count:

See Also