How to load and read files in Gradle Project.
Gradle Project Api has the following methods for using files.
file()- to load and read a particular file
files()- to load and read multiple files
fileTree()- to load and read file hierarchy in a directory or folder
zipTree()- to load and read a zip file (includes Jar , War and Ear files)
tarTree()- to load and read a tar file
How to list files inside a Zip file Jar File and Tar file
Lets say we have a file structure as shown in image below.
Following Gradle task will list the files inside a zip file, jar file and a tar file at the location "src/main/resources/archives/"
FileTree zipFiles = zipTree("src/main/resources/archives/resources.zip");
FileTree jarFiles = zipTree("src/main/resources/archives/resources.jar");
FileTree tarFiles = tarTree("src/main/resources/archives/resources.tar.gz");
println " \n#Contents of Zip File"
println " \n#Contents of Jar File"
println " \n#Contents of Tar File"
When we run the above gradle task using command
gradle -q showFiles, it will give the following
#Contents of Zip File
#Contents of Jar File
#Contents of Tar File