fun httpget(url: String): String? { val client = OkHttpClient() val request = Request.Builder().get() .url(url) .build() val call = client.newCall(request) val response = call.execute() val HTML = response.body?.string() return HTML }
肯定要有的,不然网页api以及爬虫都做不了了
0x02读取本地文件夹的文件名
1 2 3 4 5 6 7 8
fun getImgList(path: String): MutableList<String> { val files: MutableList<String> = mutableListOf() val fileTree: FileTreeWalk = File(path).walk() fileTree.maxDepth(1) .filter { it.isFile } .forEach { files.add(it.name) } return files }
示例是读取本地文件夹的图片,通过类似的思路做了个黑名单读取
1 2 3 4 5 6 7 8
fun getList(path: String): MutableList<Long> { val files: MutableList<Long> = mutableListOf() val fileTree: FileTreeWalk = File(path).walk() fileTree.maxDepth(1) .filter { it.isFile } .forEach { files.add(it.name.toLong()) } return files }