Geo*_*Geo 135 java file-io file path
我想知道Java中是否有这样的方法.以此片段为例:
// this will output a/b
System.out.println(path_join("a","b"));
// a/b
System.out.println(path_join("a","/b");
Run Code Online (Sandbox Code Playgroud)
Dan*_*ant 165
这涉及Java版本7及更早版本.
如果以后要将其作为字符串返回,可以调用getPath().实际上,如果你真的想模仿Path.Combine,你可以写下这样的东西:
public static String combine (String path1, String path2) {
File file1 = new File(path1);
File file2 = new File(file1, path2);
return file2.getPath();
}
Run Code Online (Sandbox Code Playgroud)
Pet*_*rey 102
你可以这样做
String joinedPath = new File(path1, path2).toString();
Run Code Online (Sandbox Code Playgroud)