我是靠谱客的博主 端庄服饰,这篇文章主要介绍groovy file,现在分享给大家,希望可以做个参考。

 

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def folder = new File('src/main/groovy/regina') def source = new File(folder, 'CompiledAtASTTransformation.groovy') file = new File('Listing_12_03_File_Iteration.groovy') file.each { println it } assert file.any { it =~ /File/ } assert 3 == file.findAll { it =~ /File/ }.size() assert 5 == file.grep { it }.size() file = new File('.') println file.name println file.absolutePath println file.canonicalPath println file.directory import static groovy.io.FileType.DIRECTORIES import static groovy.io.FileType.FILES def topDir = new File('../chap09') def srcDir = new File(topDir, 'src') dirs = [] srcDir.eachDir { dirs << it.name } assert ['main', 'test'] == dirs dirs = [] topDir.eachDirRecurse { dirs << it.name } assert dirs.containsAll(['gradle', 'src', 'main']) assert dirs.containsAll(['groovy', 'services', 'wrapper']) files = [] topDir.eachFile { files << it.name } assert files.contains('Listing_09_01_ToStringDetective.groovy') assert files.contains('src') File tempDir = File.createTempDir() file = new File('objects.dat') file.deleteOnExit() files = [] topDir.eachFile(FILES) { files << it.name } assert files.contains('Listing_09_01_ToStringDetective.groovy')

 

遍历demo

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
def f = new File("/shell"); def names = [] f.eachFile { names << it } for(name in names){ println name }

 

 

 

最后

以上就是端庄服饰最近收集整理的关于groovy file的全部内容,更多相关groovy内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(78)

评论列表共有 0 条评论

立即
投稿
返回
顶部