在Scala中读取基本文件属性?

Lal*_*lin 1 scala

我正在尝试使用Scala获取基本文件属性,我的参考是这个Java问题:

用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());
  }
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚的是这行代码..我不明白如何使用scala以这种方式传递类...或者为什么Java首先坚持这个而不是使用实际的构造对象作为参数.有人可以帮我写这行代码以正常运行吗?我必须使用错误的语法

val  attr = Files.readAttributes(f,Class[BasicFileAttributeView])
Run Code Online (Sandbox Code Playgroud)

Nya*_*vro 5

试试这个:

def attrs(pathStr:String) = 
  Files.getFileAttributeView(
    Paths.get(pathStr), 
    classOf[BasicFileAttributes] //corrected
  ).readAttributes
Run Code Online (Sandbox Code Playgroud)