...由于似乎两者都返回了相同的字符串-请看以下Scala代码:
scala> val f = new File("log.txt")
scala> f.getPath
// res6: String = log
scala> f.toString
// res7: String = log
最佳答案
它们是相同的。请参见javadocs。链接的直接引号:
getPath()
Converts this abstract pathname into a pathname string.
toString()
Returns the pathname string of this abstract pathname.
This is just the string returned by the getPath() method.
关于java - Java io库:File.toString()和File.getPath()有什么区别,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28206780/