从java.io.File获取java.nio.file.Path对象 [英] Get java.nio.file.Path object from java.io.File

查看:245
本文介绍了从java.io.File获取java.nio.file.Path对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从java.io.File获取Path对象?

Is it possible to get a Path object from a java.io.File?

我知道您可以使用toFile()方法将路径转换为文件,但是我找不到相反的转换.在Java 6或更低版本中有没有办法做到这一点?

I know you can convert a path to a file using toFile() method, but I couldn't find the opposite conversion. Is there a way to do this in Java 6 or lower?

推荐答案

是的,您可以从

Yes, you can get it from the File object by using File.toPath(). Keep in mind that this is only for Java 7+. Java versions 6 and below do not have it.

这篇关于从java.io.File获取java.nio.file.Path对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆