AS3 - 对文件和目录的操作
Posted dt1991
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AS3 - 对文件和目录的操作相关的知识,希望对你有一定的参考价值。
1,写入到文件
1
2
3
4
5
|
var fileObj:File = File.documentsDirectory.resolvePath( "hangge.txt" ); var fs:FileStream = new FileStream(); fs.open(fileObj, FileMode.WRITE); fs.writeUTFBytes( "hangge.com" ); fs.close(); |
2,更新文件内容
(1)下面例子在第5个字节开始覆写内容
1
2
3
4
5
6
|
var fileObj:File = File.documentsDirectory.resolvePath( "hangge.txt" ); var fs:FileStream = new FileStream(); fs.open(fileObj, FileMode.UPDATE); fs.position = 5 ; fs.writeUTFBytes( ".yuhang" ); fs.close(); |
(2)下面例子将内容添加到文件末尾
1
2
3
4
5
|
var fileObj:File = File.documentsDirectory.resolvePath( "hangge.txt" ); var fs:FileStream = new FileStream(); fs.open(fileObj, FileMode.APPEND); fs.writeUTFBytes( "www.hangge.com" ); fs.close(); |
3,读取文件内容
1
2
3
4
5
|
var fileObj:File = File.documentsDirectory.resolvePath( "hangge.txt" ); var fs:FileStream = new FileStream(); fs.open(fileObj, FileMode.READ); var str: String = fs.readUTFBytes(fs.bytesAvailable); fs.close(); |
4,移动文件
1
2
3
|
var originalFile:File = File.documentsDirectory.resolvePath( "hangge.txt" ); var newDir:File = File.applicationStorageDirectory.resolvePath( "hangge.txt" ); originalFile.moveTo(newDir); |
5,复制文件
1
2
3
|
var originalFile:File = File.documentsDirectory.resolvePath( "hangge.txt" ); var newDir:File = File.applicationStorageDirectory.resolvePath( "hangge.txt" ); originalFile.copyTo(newDir); |
6,删除文件
1
2
3
4
|
var fileObj:File = File.documentsDirectory.resolvePath( "hangge.txt" ); if (fileObj.exists){ fileObj.deleteFile(); } |
7,创建文件夹
1
2
|
var fileDir:File = File.documentsDirectory.resolvePath( "hangge" ); fileDir.createDirectory(); |
8,移动文件夹
1
2
3
|
var originalDir:File = File.documentsDirectory.resolvePath( "hangge" ); var newDir:File = File.applicationStorageDirectory.resolvePath( "hangge" ); originalDir.moveTo(newDir); |
9,复制文件夹
1
2
3
|
var originalDir:File = File.documentsDirectory.resolvePath( "hangge" ); var newDir:File = File.applicationStorageDirectory.resolvePath( "hangge" ); originalDir.copyTo(newDir); |
10,删除文件夹
1
2
3
4
|
var fileDir:File = File.documentsDirectory.resolvePath( "hangge" ); if (fileDir.exists){ fileDir.deleteDirectory(); } |
以上是关于AS3 - 对文件和目录的操作的主要内容,如果未能解决你的问题,请参考以下文章
在Tomcat的安装目录下conf目录下的server.xml文件中增加一个xml代码片段,该代码片段中每个属性的含义与用途