Forum Discussion

Nitin's avatar
Nitin
Occasional Contributor
16 years ago

read data from text file

Hi, I just started using soapui... very much new to this tool..
I wanted to read data from a file called test data.txt. I stored this file on C:\

Following command gives - file not found exception..
new File( "C:\\testdata.txt" ).eachLine { line -> list.add( line ) }

Whats wrong? Please help.

3 Replies

  • Nitin's avatar
    Nitin
    Occasional Contributor
    This id done now. Actually it is not working with txt file... i tried with .doc, and it worked!
    weired groovy!! (or I missed something??)
  • Nitin's avatar
    Nitin
    Occasional Contributor
    my testdata.doc file contains - Line1
    Line2
    Line3
    Line4
    Line5
    Line6
    Line7
    Line8
    Line9
    Line10


    def list = []
    def f=new File( "C:\\testdata.doc" )

    f.eachLine { line -> list.add( line ) }
    log.info "start"
    log.info list[0]
    log.info list[1]
    log.info list[2]
    log.info list[3]
    log.info list[4]
    log.info list[5]
    log.info list[6]
    log.info list[7]
    log.info list[8]
    log.info list[9]
    log.info list[10]

    The above program displays results with strange characters... any idea? any other way to read file sequentially line by line?? or reading excel would be best! please post the code if u have, or suggest!
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    If you are using a .doc file, I think the strange characters are formatting characters that are normally invisible in an editor. I think the simplest solution would be to save your data as a .txt file, and use that.

    /Nenad
    http://eviware.com