This shows you the differences between two versions of the page.
sample_code:random_file_acces [2015/07/08 09:18] octazid created |
sample_code:random_file_acces [2018/02/22 19:58] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Low Level Random File Access ====== | ||
- | //(Posted by Dave Smart in the DroidScript-Betatesters google group)// | ||
- | |||
- | Hi Guys, | ||
- | |||
- | We were asked to include low level random file access by Henrik and decided to jam it in very quickly since others might also find it useful. | ||
- | |||
- | Here is some info about it: | ||
- | |||
- | <code javascript> | ||
- | function btn_OnTouch() | ||
- | { | ||
- | var file = app.CreateFile( "/ | ||
- | |||
- | file.WriteText( " | ||
- | var len = file.GetLength(); | ||
- | console.log( "file len: " + len ); | ||
- | |||
- | file.Seek( len ); | ||
- | file.WriteNumber( 77, " | ||
- | file.WriteData( " | ||
- | |||
- | file.Seek( 0 ); | ||
- | var data = file.ReadData( 2 ); | ||
- | console.log( "first two bytes:" | ||
- | |||
- | file.Seek( 0 ); | ||
- | alert( file.ReadText( " | ||
- | |||
- | file.Close(); | ||
- | } | ||
- | </ | ||
- | |||
- | And here are some Java code snippets which will have to serve as documentation for now: | ||
- | |||
- | <code java> | ||
- | |||
- | public void Close() | ||
- | |||
- | public void Seek( long offset ) | ||
- | |||
- | public long GetLength() | ||
- | |||
- | public void SetLength( long len ) | ||
- | |||
- | //Write text to file. | ||
- | //types: " | ||
- | // | ||
- | // | ||
- | public void WriteText( String data, String type ) throws Exception | ||
- | |||
- | //Read text from file. | ||
- | //types: " | ||
- | // | ||
- | // | ||
- | |||
- | //Write binary data to file. | ||
- | //eg. " | ||
- | // " | ||
- | // " | ||
- | public void WriteData( String data, String mode ) throws Exception | ||
- | |||
- | //Read binary data from file. | ||
- | //Modes: " | ||
- | public String ReadData( int len, String mode ) | ||
- | |||
- | //Write numeric data to file (LE means little endian) | ||
- | // | ||
- | // " | ||
- | public void WriteNumber( double data, String type ) | ||
- | |||
- | |||
- | //Read numeric data from file | ||
- | // | ||
- | // " | ||
- | public double ReadNumber( String type ) | ||
- | </ | ||
- | |||
- | I've just added file.GetPointer() and file.Skip() | ||
- | |||
- | More infos: [[http:// |