我正在尝试读取一个名为:K2ssal.timestamp 的文件。 我想将文件名的时间戳部分作为通配符处理。 我怎样才能做到这一点? 尝试在文件名后加 * 但不起作用。
var getK2SSal: Iterator[String] = Source.fromFile("C://Users/nrakhad/Desktop/Work/Data stage migration/Input files/K2Ssal.*").getLines()
最佳答案
您可以将Files.newDirectoryStream
与目录+ glob一起使用:
import java.nio.file.{Paths, Files}
val yourFile = Files.newDirectoryStream(
Paths.get("/path/to/the/directory"), // where is the file?
"K2Ssal.*" // glob of the file name
).iterator.next // get first match
关于java - 文件通配符使用 *,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51441199/