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", "Char" );
    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 ( “/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
String
List: [ bytes ]
Object: { COMMAND }
function( data )
fil.Batch
Batch method calls to be able to set all object's properties at once.
Note that you need to specify each parameter (use “” or null to leave some out)
Inherited methods can be called by appending an underscore to the function name (ie. txt.Batch({ SetBackColor_: [“red”] })
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