一、项目目录的路径获取
println "the root file path is"+ getRootDir().absolutePathprintln "the build file path is"+getBuildDir().absolutePathprintln "the project file path is"+ getProjectDir().absolutePath

二、获取文件内容
println getContent('local.properties')def getContent(String path){try{def file=file(path)return file.text}catch(GradleException e){println 'file not found'}return null}
跟New File一样,好处是无需传绝对路径,只需要传项目跟目录下得路径即可(相对路径)
三、拷贝文件
copy{from file("app/build/outputs/apk/")into getRootProject().getBuildDir().path +"/apk/"exclude{} //排除某些文件rename{} //重命名}
可以用来打包后拷贝apk
四、对文件树进行遍历
//对文件树进行遍历fileTree('build'){FileTree fileTree->fileTree.visit{ FileTreeElement element->println "this file name is :" + element.file.name}}
