<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    keep moving!

    We must not cease from exploration. And the end of all our exploring will be to arrive where we began and to know the place for the first time.
    隨筆 - 37, 文章 - 2, 評論 - 3, 引用 - 0
    數據加載中……

    groovy操作文件及xml

    /**
     * 參考資料
     * Groovy之旅系列
     * Groovy之invokeMethod
     */

    //讀取文件內容1
    number = 0
    new File("src/FileExample.groovy").eachLine({
        line ->
        number ++
        println("$number:$line")
    })

    //讀取文件內容2
    println new File("src/FileExample.groovy").getText()

    //創建目錄
    import static  java.io.File.separator as sep  
    new File(System.properties.'user.home'+sep+'.11groovy'+sep+'lib').mkdirs()

    //寫入文件
    def outFile = new File('mydata.txt')
    def printWriter = outFile.newPrintWriter()
    printWriter.println("面朝大海, 春暖花開!")
    printWriter.flush()
    printWriter.close()

    /**
     * 讀取xml文件
    <?xml version="1.0" ?>
    <customers>
      <corporate>
        <customer name="Bill Gates"        company="Microsoft" />   
        <customer name="Steve Jobs"        company="Apple" />
        <customer name="Jonathan Schwartz" company="Sun" />
      </corporate>
      <consumer>
        <customer name="John Doe" />
        <customer name="Jane Doe" />
      </consumer>
    </customers>
     */
    def customers = new XmlSlurper().parse(new File("src/customer.xml"))
    for(customer in customers.corporate.customer)
    {
        println "${customer.@name} works for ${customer.@company}";
    }

    //寫入xml文件,使用大括號{}將生成標簽,使用在括號()用來定義屬性。
    import groovy.xml.MarkupBuilder
    def writer = new StringWriter()
    def xml = new MarkupBuilder(writer)
    xml.records() {
     car(name:'polo', maker:'Shanghai Volkswagen', year:2006) {
      price('&26000')
      comment('a good car for you')
     }
     car(name:'camry', make:'Toyota', year:2005) {
      price('$19000')
      comment('The low petrol consumption cars ')
     }
    }
    println writer.toString()

    posted on 2008-09-01 12:51 大石頭 閱讀(1677) 評論(0)  編輯  收藏 所屬分類: Groovy

    主站蜘蛛池模板: 亚洲人成日本在线观看| 在线观看免费亚洲| 亚洲宅男永久在线| 日本在线高清免费爱做网站| 亚洲欧美aⅴ在线资源| 一区二区免费视频| 国产亚洲成AV人片在线观黄桃| 99爱免费观看视频在线| jizzjizz亚洲日本少妇| 亚洲国产精品一区二区成人片国内| 九九综合VA免费看| 亚洲高清日韩精品第一区| 又粗又大又长又爽免费视频| 91成人免费观看| 亚洲精品二三区伊人久久| 亚洲精品乱码久久久久久不卡| 99久久99久久精品免费看蜜桃| 亚洲精品中文字幕无乱码| www国产亚洲精品久久久| 91青青青国产在观免费影视| 边摸边吃奶边做爽免费视频网站| 亚洲一区免费观看| 红杏亚洲影院一区二区三区| 日韩免费一区二区三区在线播放| aa在线免费观看| 亚洲免费视频网站| 国产h视频在线观看网站免费| 国产精品福利在线观看免费不卡| 在线精品亚洲一区二区小说| 成人免费无码大片A毛片抽搐 | 美女被免费网站91色| 亚洲熟女乱色一区二区三区| 亚洲视频在线观看免费| 亚洲精品成人在线| 国产一级淫片a免费播放口之| 亚洲天堂免费在线| 18禁止看的免费污网站| 青青操免费在线视频| 免费人成大片在线观看播放电影| 97se亚洲国产综合自在线| 亚洲综合精品一二三区在线|