-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathRead_Write.as
More file actions
46 lines (44 loc) · 965 Bytes
/
Read_Write.as
File metadata and controls
46 lines (44 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package file
{
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.utils.ByteArray;
public class Read_Write
{
public static function read(Path_p:File):ByteArray
{
if(!Path_p.exists)
{
return null
}
var _byteArray:ByteArray = new ByteArray()
var _stream:FileStream = new FileStream()
_stream.open(Path_p,FileMode.READ)
_stream.readBytes(_byteArray)
_stream.close()
_byteArray.position = 0
return _byteArray
}
public static function write(Path_p:File,ByteArray_p:ByteArray):String
{
try
{
if(Path_p.exists)
{
Path_p.deleteFile()
}
var _stream:FileStream = new FileStream()
_stream.open(Path_p,FileMode.WRITE)
ByteArray_p.position = 0
_stream.writeBytes(ByteArray_p,0,ByteArray_p.bytesAvailable)
_stream.close()
}
catch(event:Error)
{
return event.message;
}
return '';
}
}
}