我正在尝试使用 Scala 获取基本文件属性,我的引用是这个 Java 问题:
Determine file creation date in Java
我正在尝试用 Scala 重写这段代码:
static void getAttributes(String pathStr) throws IOException {
Path p = Paths.get(pathStr);
BasicFileAttributes view
= Files.getFileAttributeView(p, BasicFileAttributeView.class)
.readAttributes();
System.out.println(view.creationTime()+" is the same as "+view.lastModifiedTime());
}
我无法弄清楚的是这行代码..我不明白如何使用 scala 以这种方式传递类...或者为什么 Java 首先坚持这一点而不是使用实际构造的对象作为参数。有人可以帮我编写这行代码以使其正常运行吗?我一定使用了错误的语法
val attr = Files.readAttributes(f,Class[BasicFileAttributeView])
最佳答案
试试这个:
def attrs(pathStr:String) =
Files.getFileAttributeView(
Paths.get(pathStr),
classOf[BasicFileAttributes] //corrected
).readAttributes
关于scala - 在 Scala 中读取基本文件属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34080959/