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) collision courthrows 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 = newvi是什么 File("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."));offer的用法 printPaths(file); // 南泰贤下面的URI将报错,file协议类型文件地址必须使用“correct/”,在windows下文件路径也必须以“/”开始 // file =new File(new URI("file:///D:\\gits\\commons-io-2.4\\w1.txt")); } private static void unixFormatTest() throws IOException, URISyntaxException { File file =世界人口将在2064年达到峰值 new File("/Urs/"); printPaths(file); // relative path file = new File("test.xsd"); printPathsielts官网(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.out.println("Absolute Path: " + file.getAbsolutePath()); System.outbarcarolle.println("Canonical Path: " + file.getCanonicalPath()); System.out.println("Path: " + file.getPath()); System.out.printlnproduction(); } 东南方} |
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. 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:\gits\.\..\gits\commons-io-2. Canonical Path: D:\gits\commons-io-2. Path: D:\gits\.\..\gits\commons-io-2. Absolute Path: D:\gits\commons-io-2. Canonical Path: D:\gits\commons-io-2. Path: D:\gits\commons-io-2. |
本文发布于:2023-05-25 15:34:03,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/fan/90/122272.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |