| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1462 人关注过本帖
标题:关于Fwrite()的问题
只看楼主 加入收藏
pjtyzyq
Rank: 4
等 级:业余侠客
威 望:6
帖 子:232
专家分:240
注 册:2016-2-14
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
关于Fwrite()的问题
这是VFP帮助里的例子,加了一行“FWRITE(gnFileHandle, "abcd" )”,希望将字符串“abcd”写入文件,却没有成功,问题出在哪?
Local gnFileHandle,nSize,cString
gnFileHandle = FOPEN("D:\kejian\file_s\sd.txt")
* Seek to end of file to determine number of bytes in the file.
nSize =  FSEEK(gnFileHandle, 0, 2)     && 移动指针到末尾
IF nSize <= 0
 * If file is empty, display an error message.
 WAIT WINDOW "This file is empty!" NOWAIT
ELSE
 * If file is not empty, store the file's contents in memory
 * and display the text in the main Visual FoxPro window.
 = FSEEK(gnFileHandle, 0, 0)      && 移动指针到开始
 cString = FREAD(gnFileHandle, nSize)
  =FWRITE(gnFileHandle, "abcd" )
ENDIF
= FCLOSE(gnFileHandle)         && 关闭文件

[此贴子已经被作者于2021-4-28 20:24编辑过]

搜索更多相关主题的帖子: IF 指针 Fwrite the file 
2021-04-28 20:22
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:335
帖 子:9798
专家分:26886
注 册:2012-2-5
收藏
得分:20 
gnFileHandle = FOPEN("D:\kejian\file_s\sd.txt", 12) && 默认为 0 ,只读

坚守VFP最后的阵地
2021-04-28 20:46
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:335
帖 子:9798
专家分:26886
注 册:2012-2-5
收藏
得分:0 
fopen( ) 函数示例
if file('errors.txt')  && 文件存在吗?
    gnerrfile = fopen('errors.txt',12)  && 如果存在,以读写方式打开
else
    gnerrfile = fcreate('errors.txt')  && 如果不存在,创建文件
endif
if gnerrfile < 0  && 检查文件打开时的错误
    wait 'cannot open or create output file' window nowait
else  && 如果没有错误,则写文件
    =fwrite(gnerrfile, 'error information to be written here')
endif
=fclose(gnerrfile)  && 关闭文件
modify file errors.txt nowait  && 在编辑窗口中打开文件

坚守VFP最后的阵地
2021-04-28 20:51
pjtyzyq
Rank: 4
等 级:业余侠客
威 望:6
帖 子:232
专家分:240
注 册:2016-2-14
收藏
得分:0 
回复 2楼 sdta
谢谢!
2021-04-28 20:55
快速回复:关于Fwrite()的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017082 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved