本文介绍了在 Java7 中从字符串创建路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建java.nio.file.Path
对象来自 Java 7 中的 String
对象?
即
String textPath = "c:/dir1/dir2/dir3";
Path path = ?;
其中 ?
是使用 textPath
的缺失代码.
where ?
is the missing code that uses textPath
.
推荐答案
你可以直接使用 Paths
类:
You can just use the Paths
class:
Path path = Paths.get(textPath);
...当然,假设您想使用默认文件系统.
... assuming you want to use the default file system, of course.
这篇关于在 Java7 中从字符串创建路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!