关于文件问题

mili2003 2003-09-30 08:41:58
有很多软件(大多是游戏),可以将很多声音文件、图片文件放到一个大的文件中,用的时候从这个大文件中读取,请问在vb中怎样办????/
...全文
34 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
feiqinfeiwhw 2003-09-30
  • 打赏
  • 举报
回复
str="c:/aa.txt"
lngtmp=freefile()
dim byt() as byte
dim lngsize as long
open str for binary access read as #lngtmp
lngsize=lof(1)
redim byt(lngszie) as byte
put #lngtmp,,byt
close #lngtmp
那byt中存的就是文件信息,不过是二进制的
如果要不是二进制的可以这样
dim strfile as string
lngtmp=freefile()
open str for binary access read as #lngtmp
strfile=cstr(input(lof(lngtmp),lngtmp))
close #lngtmp
这样strfile中存的就是该文件的信息
射天狼 2003-09-30
  • 打赏
  • 举报
回复
用资源文件,编译到资源文件里就行了~~
sundylong 2003-09-30
  • 打赏
  • 举报
回复
如下方法保存:(将下面得代码拷入一个*.TXT文档,保存为*.Frm)
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 6795
ClientLeft = 60
ClientTop = 450
ClientWidth = 8175
LinkTopic = "Form1"
ScaleHeight = 6795
ScaleWidth = 8175
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text1
Height = 435
Left = 1680
TabIndex = 4
Text = "要保存得文字"
Top = 4560
Width = 4095
End
Begin VB.PictureBox Picture1
Height = 4350
Left = 1680
Picture = "Form1.frx":0000
ScaleHeight = 4290
ScaleWidth = 4050
TabIndex = 3
ToolTipText = "要保存得图片"
Top = 120
Width = 4110
End
Begin VB.CommandButton Command3
Caption = "读取"
Height = 555
Left = 120
TabIndex = 2
Top = 1440
Width = 1455
End
Begin VB.CommandButton Command2
Caption = "清空"
Height = 555
Left = 120
TabIndex = 1
Top = 780
Width = 1455
End
Begin VB.CommandButton Command1
Caption = "保存"
Height = 555
Left = 120
TabIndex = 0
Top = 120
Width = 1455
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Const sCombinedFile = "E:\combined.dat"
Const sTmpPix = "E:\picxtract.bmp"


Private Sub Command1_Click()

Dim nImageSize As Long
Dim hFile As Long

'save the picture portion as the first entry
'in the "combined file"
SavePicture Picture1.Picture, sCombinedFile

'Open the combined file for append in order to
'add the text to file
hFile = FreeFile

Open sCombinedFile For Binary As #hFile

'Retrieve the size of the image into a
'variable for later use, then append the
'text into the same file.
nImageSize = LOF(hFile)
Seek #hFile, nImageSize + 1
Put #hFile, , Text1.Text

'The file now contains both the image
'and text file. As a final step, we
'save the length of image retrieved
'above as the last item in the file.
Seek #hFile, LOF(hFile)
Put #hFile, LOF(hFile) + 1, nImageSize

Close #hFile

End Sub


Private Sub Command2_Click()

Set Picture1.Picture = Nothing
Text1.Text = ""

End Sub


Private Sub Command3_Click()

Dim nImageSize As Long
Dim hFile As Long
Dim hFileOut As Long
Dim PicData() As Byte

'First step in the extraction process is to
'obtain the length of image portion saved
'as the last item in the file.
hFile = FreeFile
Open sCombinedFile For Binary As #hFile

'move to the LOF - 3 and load the
'saved image size
Seek #hFile, LOF(hFile) - 3
Get #hFile, , nImageSize

'with the image size, create a byte array
'large enough to accommodate the image
ReDim PicData(0 To nImageSize - 1) As Byte

'and load the image data, repositioning the
'file pointer to the beginning first
Seek #hFile, 1
Get #hFile, , PicData()

'write the pix to a temporary file in
'order to use the LoadPicture method.
hFileOut = FreeFile
Open sTmpPix For Binary As #hFileOut
Put #hFileOut, , PicData()
Close #hFileOut

'load the text portion to the textbox. The
'text begins immediately after the image, and
'extends for the file length minus the trailing
'4 bytes for the Long that stored the image size.
Seek #hFile, nImageSize + 1
Text1.Text = Input(LOF(hFile) - nImageSize - 4, hFile)

Close #hFile

'Load the saved image from the tmp file
'and kill it
Picture1 = LoadPicture(sTmpPix)
Kill sTmpPix

End Sub

Re: 《文件备份与压缩命令》 ---------------------------------------内容提要: 1/6)tar   命令:打包备份/解压打包(将文件或目录的压缩或不解压查看查看)2/6)gzip  命令:压缩或解压文件3/6)zip   命令:打包和压缩文件4/6)unzip 命令:解压zip文件5/6)scp   命令:远程文件复制(全量备份)6/6)rsync 命令:文件同步工具(增量备份)  本人在教学和实战过程中发现,即便是有一定运维经验的人,可能已经能够搭建一定复杂度的Linux架构,但是在来来回回的具体操作中,还是体现出CLI(命令界面)功底不够扎实,甚至操作的非常‘拙’、处处露‘怯’。 对一个士兵来说,枪就是他的武器,对于一个程序员来说,各种library(工具库)就是他的武器;而对于Linux运维人员来说,无疑命令行工具CLI(命令界面)就是他们的武器;高手和小白之间的差距往往就体现在对于这些“武器”的掌握和熟练程度上。有时候一个参数就能够解决的事情,小白们可能要写一个复杂的Shell脚本才能搞定,这就是对CLI(命令界面)没有理解参悟透彻导致。 研磨每一个命令就是擦拭手中的作战武器,平时不保养不理解,等到作战的时候,一定不能够将手中的武器发挥到最好,所以我们要平心、静气和专注,甘坐冷板凳一段时间,才能练就一身非凡的内功! 本教程从实战出发,结合当下流行或最新的Linux(v6/7/8 版本)同时演示,将命令行结合到解决企业实战问题中来,体现出教学注重实战的务实精神,希望从事或未来从事运维的同学,能够认真仔细的学完Linux核心命令的整套课程。 本课程系列将逐步推出,看看我教学的进度和您学习的步伐,孰占鳌头! 注:关于教学环境搭建,可以参考本人其它课程系列,本教学中就不再赘述! 《参透 VMware 桌面级虚拟化》 《在虚拟机中安装模版机(包括应用软件等)》 《SecureCRT 连接 GNS3/Linux 的安全精密工具》

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧