zoukankan      html  css  js  c++  java
  • ruby读写txt文件

     # Part one

    aFile = File.new("C:\\1.txt","w")
           aFile.puts "the 1"
           aFile.puts "the 2"
    aFile.close
     
    # Part two
    aFile = File.new("C:\\2.txt","w")
           puts "the 1"
           puts "the 2"
    aFile.close

    闲的无聊,看了一下Ruby如何读写文件,准备写段代码来生成测试数据。上面有两段代码,看出有什么区别吗?嗯,一个用了 aFile.puts 而另外一个是 puts 。在执行的时候发现只有 Part one 的代码会把字符串写到文档里面,而 Part two 的代码只是把字符串打印在屏幕上。不知道是否在不指定I/O的情况下 Ruby 使用标准的 I/O 作为了默认的输入、输出。有兴趣的朋友可以直接copy这段代码到 Ruby 的 IDE 里面执行一下看看效果。

    另外,要注意文件路径的书写格式,是“\\”而不是“\”。比如:system("c:\\test.bat")

    http://www.cnblogs.com/jackei/archive/2006/08/23/484732.html
      
  • 相关阅读:
    四则运算测试脚本运行情况
    AAA
    (2015秋) 软工作业成绩公布(12月26号更新)
    判断闰年的Java算法
    B
    A
    Where Amazing Happens
    安利一发资料站
    C
    B
  • 原文地址:https://www.cnblogs.com/zhuque/p/2957077.html
Copyright © 2011-2022 走看看