用户名: 密码: 免费注册 忘记密码? 网站地图 | 加入收藏 | 设为首页
首页 | 新闻 | 工具 | 系统 | 办公 | 聊天 | 多媒体 | 网页 | 运营 | 平面 | 欣赏 | 数据库 | 程序 | 服务器 | 组网
网页 | 3dmax | Ghost | Windows Xp| Dreamweaver | photoshop | Flash | office | Alexa | Css | QQ | Asp | PHP | Jsp | Access
Flash MX 2004入门 | 网站推广策略 | CorelDRAW入门 | ASP学习 | 网站建设大师功 | Word入门
  iTbulo.com > 学院 > 多媒体教程 > Director教程 > 文章正文
用FileIO读取二进制数据(二)
iTbulo.COM 2006-1-12 dcm/翻译、整理()

在前一篇文章里,我们讨论了如何利用FileIO从非文本文件中读取数据的问题,本次我们讨论用FileIO编辑现有文件,例如MP3文件上,或是创建新文件,例如从Director 的cast member中输出位图文件。

编辑MP3文件

写二进制文件最简单的例子莫过于编辑MP3文件的标签。这总比新建文件要来得简单,你不必去弄清整个文件结构,只需明白歌曲信息是储存在最后128个字节里。

on writeBinaryFile filePath, byteList, fileStartByte, listStartByte, deleteOriginalFile

result = 0
fileObj = new (xtra "fileIO")
if deleteOriginalFile then
-- It's often "cleaner" to remove the existing file
-- though you obviously wouldn't do this when editing
-- an MP3 file
fileObj.openFile (filePath, 0)
fileObj.delete ()
fileObj.createFile (filePath)
end if
fileObj.openFile (filePath, 2)
-- Attempt to open the file with write-only access

if fileObj.status () = 0 then
listLength = byteList.count
if fileStartByte.voidP then fileStartByte = 1
-- Set default positions if none were supplied via
-- the fileStartByte & listStartByte parameters
if listStartByte.voidP then listStartByte = 1

fileObj.setPosition (fileStartByte-1)
-- Set the write position in the file & begin dumping
-- the list contents into the file

repeat with index = listStartByte to listLength
fileObj.writeChar (numToChar (byteList[index]))
end repeat
result = 1
end if

fileObj.closeFile ()
fileObj = 0
return result
end

[1] [2] 下一页

文章搜索
相关资讯
相关文章 相关下载
DIRECTOR去背技法步步高(二)
DIRECTOR去背技法步步高(一)
Director怎样制作自定义光标
Director 3D 基础(之七)
Director 3D 基础(之六)
焦点信息