groovy file类

File 类介绍java

  一、抽象路径名:File类提供抽象的,独立于系统的分级路径名闭包

  D:/clat/test.groovy(注意抽象路径名使用/,不是/ )app

  二、File能够表示文件或目录 对象

  三、Groovy对java.io.File进行了加强(参考GDK Doc)递归

       def toysFile = new File("src/TestToysFile.dat")字符串

       if(!toysFile.exists()){get

            toysFile.createNewFile()it

            toysFile.append('Groovy and clat' + '/n')io

       }test

  四、File类的其余经常使用方法

  • Boolean delete():删除文件或目录
  • void eachFile(Closure cl):目录中每一个文件应用闭包
  • void eachFileResurse(Closure cl):同上并对子目录递归
  • void eachLine(Closure cl):逐行遍历文件并应用闭包
  • String getPath():将抽象路径名称转换为路径名字符串。
  • String getText():读文件返回字符串
  • Boolean isDirectory():是否目录
  • Boolean mkdir():建立目录
  • void deleteDir();删除目录及目录下的全部内容
  • void withPrintWriter(Closure cl):获取打印速写器。//具体不明,能够查API

写多个对象到文件的方法

  一、基础知识:将对象序列化到文件时,若是多个对象序列化到同一个文件,会覆盖头部信息,使得读取对象失败,因此要作处理。

  还未写demo,之后补充

相关文章
相关标签/搜索