Back

CreateFile

Hello World
Content:
- Methods

Returns a File object.

fil = app.CreateFile( file, mode ) → app object: File

Example - Example

function btn_OnTouch()
{
    var file = app.CreateFile( "/sdcard/test.txt", "rw" );

    file.WriteText( "Hello", "Chars" );
    var len = file.GetLength();
    console.log( "file len: " + len );

    file.Seek( len );
    file.WriteNumber( 77, "Byte" );
    file.WriteData( "66,121,101", "Int" );

    file.Seek( 0 );
    var data = file.ReadData( 2 );
    console.log( "first two bytes:" + data[0] + "," + data[1] );

    file.Seek( 0 );
    alert( file.ReadText( "Line" ) );

    file.Close();
}
Copy All       Run      

Methods

The following methods are available on the File object:

Close()
GetLength() → number: Bytes
GetType() → string: “File”
ReadNumber( type ) → number
ReadText( type ) → string
Skip( bytes )
number
number: integer
string: path to file or folder ( “/absolute/...” or “relative/...” )
string: “r” or “w” or “rw”
string: “Int” or “Text” or “Hex”
string: “Byte” or “UByte” or “Bool” or “Float” or “FloatLE” or “Long” or “LongLE” or “Short” or “UShort” or “ShortLE” or “UShortLE” or “Int” or “UInt” or “IntLE”
string: UTF, Line or Char
string: Line or Char
string: “FA,FB,FC” or “250,251,252” or abc46
string: “Hex” or “Int” or “Text”
string: UTF, Bytes or Char
function( data )
fil.Close
Close File
fil.GetLength
Returns the file size in bytes.
fil.GetPointer
Returns the current pointer position in the file.
fil.GetType
Returns the control class name.
fil.ReadData
Reads a amount of bytes from the file.
fil.ReadNumber
Read numeric data from file.
fil.ReadText
Read data from the file as text.
fil.ReadTextAsync
Asynchronously reads a single character or a line as text.
fil.Seek
CHange pointer position to a given byte in the file.
fil.SetLength
Allocate memory for a file.
fil.Skip
Let the pointer skip a given number of bytes.
fil.WriteData
Write data to the file.
fil.WriteNumber
Writes a number to the file.
fil.WriteText
writes text to file