zoukankan      html  css  js  c++  java
  • QTP操作txt文档

    QTP可以在txt文件(文本文件中读取数据)

    首先创造一个文档对象 set fso = createObject("scripting.filesystemobject")

    然后用此对象打开目标文档 Set txt = fso.OpenTextFile( "C:Documents and SettingsAdministrator桌面 est.txt",8,true)

    这里说一说OpenTextFile方法,根据QTP的帮助文档中记载

    根据以上帮助文档记录,我们现在要实现的是读取一个txt文档,OpenTextFile方法里的iomode模式采用只读模式(ForReading|1)代码如下:

    Option explicit
    Dim fso 
    set fso = createObject("scripting.filesystemobject")
    Dim txt
    Set txt = fso.OpenTextFile( "C:Documents and SettingsAdministrator桌面	est.txt",1,true)
    'Skips the next line when reading a TextStream file.忽略掉文档中的第一行
    'txt.SkipLine
    Dim content
    While not txt.AtEndOfStream
    	'读取txt文档中的一行
    	content =   txt.ReadLine
    	print(content)
    	print("------------------------")
    Wend
    txt.Close
    Set txt = nothing
    Set fso = nothing
    

    好了,上述操作即实现了对txt文档的读取操作。

    接着,我们实现向txt文档写入内容的操作,iomode采用写入的模式ForWriting|2和ForAppending|8都可以。实现代码如下:

    Option explicit
    Dim fso 
    set fso = createObject("scripting.filesystemobject")
    Dim txt
    Set txt = fso.OpenTextFile( "C:Documents and SettingsAdministrator桌面	est.txt",8,true)
    txt.WriteLine("This is a new line")
    txt.Close
    Set txt = nothing
    Set fso = nothing
    
  • 相关阅读:
    apache+mysql+php+phpmyadmin搭建
    Redis学习笔记(1)Redis安装和启动
    Zlib 引用中出现的问题
    约数
    AC自动机
    当我们说“一切皆对象”时,我们到底在说什么
    Google翻译,3个步骤灭绝人类
    Linux下Gcc生成和使用静态库和动态库详解(转)
    Java基础&笔试题
    SQL基础&笔试题
  • 原文地址:https://www.cnblogs.com/huang1990/p/3686153.html
Copyright © 2011-2022 走看看