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("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); // 下面的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 = 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.out.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-19 01:53:50,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/fan/89/915086.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |