关于文件打开方式的问题

swazyl 2003-12-09 12:09:58
我用这条语句li_FileNum = FileOpen("d:\bbsczzgl\programupdate.ini",linemode!, write!, lockWrite!, replace!)
来打开一个Ini文件,但奇怪的是每次打开之后,文件内容都变为空了(但我把write!改为read!又没这个问题)所以用下面这条语句读取文件之后,li_bytes返回为-1,
i_bytes = FileRead(li_FileNum, version),不知为什么?
...全文
52 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
CodeMagic 2003-12-09
  • 打赏
  • 举报
回复
出错的地方在于你设置了replace!参数,该参数在写模式下会清空原有文件的全部内容,多看看帮助就清楚了。

至于FileRead(li_FileNum, version)返回-1,我想应该是文件句柄li_FileNum不正确所致。
hzhxxx 2003-12-09
  • 打赏
  • 举报
回复
没有中文的了,只有这样
hzhxxx 2003-12-09
  • 打赏
  • 举报
回复
Description

Opens the specified file for reading or writing and assigns it a unique integer file number. You use this integer to identify the file when you read, write, or close the file. The optional arguments filemode, fileaccess, filelock, and writemode determine the mode in which the file is opened.

Syntax

FileOpen ( filename {, filemode {, fileaccess {, filelock {, writemode
{ creator, filetype }}}}} )

Argument Description
filename A string whose value is the name of the file you want to open. If filename is not on the current directory's relative search path, you must enter the fully qualified name
filemode (optional) A value of the FileMode enumerated type that specifies how the end of a FileRead or FileWrite is determined. Values are:?LineMode! ?(Default) Read or write the file a line at a time?StreamMode! ?Read the file in 32K chunksFor more information, see Usage below
fileaccess
(optional) A value of the FileAccess enumerated type that specifies whether the file is opened for reading or writing. Values are:?Read! ?(Default) Read-only access?Write! ?Write-only accessIf PowerBuilder doesn't find the file, a new file is created if the fileaccess argument is set to Write!
filelock (optional) A value of the FileLock enumerated type specifying whether others have access to the opened file. Values are:?LockReadWrite! ?(Default) Only the user who opened the file has access?LockRead! ?Only the user who opened the file can read it, but everyone has write access?LockWrite! ?Only the user who opened the file can write to it, but everyone has read access?Shared! ?All users have read and write access
writemode (optional) A value of the WriteMode enumerated data type. When fileaccess is Write!, specifies whether existing data in the file is overwritten. Values are:?Append! ?(Default) Write data to the end of the file?Replace! ?Replace all existing data in the fileWritemode is ignored if the fileaccess argument is Read!
Return value

Integer. Returns the file number assigned to filename if it succeeds and -1 if an error occurs. If any argument's value is NULL, FileOpen returns NULL.

Usage

When a file has been opened in line mode, each call to the FileRead function reads until it encounters a carriage return (CR), linefeed (LF), or end-of-file mark (EOF). Each call to FileWrite adds a CR and LF at the end of each string it writes.
When a file has been opened in stream mode, a call to FileRead reads the whole file (until it encounters an EOF) or 32,765 bytes, whichever is less. FileWrite writes a maximum of 32,765 bytes in a single call and does not add CR and LF characters.

File not found If PowerBuilder doesn't find the file, it creates a new file, giving it the specified name, if the fileaccess argument is set to Write!.


仔细看看
freedom2001 2003-12-09
  • 打赏
  • 举报
回复
去看PB6用户手册吧,那本书就是把PB的E文帮助给翻译出来了,书中提到的的东西在各个版本都适用,看完你就知道为什么错了
mittee 2003-12-09
  • 打赏
  • 举报
回复
参数错了

replace!-〉 Append!
wht8008 2003-12-09
  • 打赏
  • 举报
回复
用api,可以打开window能打开的所有的文件
ll_rtn = ShellExecuteA (Handle(Parent),'open',文件名称,'','',1)
if ls_open=31 or ls_open=3 then//如果系统找不到打开程序,则弹出打开方式的对话框
Run("rundll32.exe Shell32.dll,OpenAs_RunDLL "+文件名称, Maximized!)
end if
swazyl 2003-12-09
  • 打赏
  • 举报
回复
CodeMagic(写错了吧) ,你说出错的地方在于设置了replace!参数,我是要设置这个参数,因为打开之后,我要根据具体情况用新的内容来覆盖原来的内容,但是我是在fileopen里头加这个参数,还没有写呀,只是打开怎么就把原来的内容清空了.

1,077

社区成员

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

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