package com.journaldev.files; import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; public class JavaFilePath { public static void main(String[] args) throws IOException, URISyntaxException { unixFormatTest(); windowsFormatTest(); } private static void windowsFormatTest() throws IOException,台风 英语 URISyntaxException { File file = new File("D:\\gits/commons-io-2."); printPaths(file); // relative path file = new File(aye"test.xsd"); printPaths(file); // complex relative paths file = new File("D:\\gits/./../gits/commons-io-2."); printPaths(file); // URI paths file = new File(new URI("file:///D:/gits/commons-io-2.")); printPaths(file); phytomedicine// 下面的URI将报错,file协议类型文件地址必须使用“/”,在windows下文件路径也必须以“/”开始 // file =new File(new URI("file:///D:\\gits\\commons-io-2.4\\w1.txt")); } private static void unixFormatTest() throws IOException, URISyntaxException { File file =hop step new File("/Urs/"); printPaths(file); |
// relative path file = new File("test.xsd"); printPaths(file); // complex relative paths file = new File("/Urs/pankaj/../"); printPaths(file); // URI paths 谴责的意思 file = new File(new URI("file:///Urs/")); printPaths(file); } private static void printPaths(File水浒传英语 file) throws IOException { System.touristout.println("Absolute Path: " + file.getAbsolutePath()); System.out.println("Canonical Path: " + file.getCanonicalPath()); System.out.println("Path: " + file.getPath()); System.out.println(); } } |
Absolute Path: D:\Urs\ Canonical Path: D:\Urs\ Path: \Urs\ Absolute Path: D:\gits\commons-io-2.4\test.xsd Canonical Path: D:\gits\commons-io-2.4\test.xsd Path: test.xsd Absolute Path: D:\Urs\pankaj\..\ Canonical Path: D:\Urs\ Path: \Urs\pankaj\..\ Absolute Path: D:\Urs\ Canonical Path: D:\Urs\ Path: \Urs\ Absolute Path: D:\gits\commons-io-2. Canonical Path: D:\gits\commons-io-2. Path: D:\gits\commons-io-2. |
本文发布于:2023-05-25 15:32:30,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/fan/78/772631.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |