java get file path from string
Look at the methods in the java.io.File class: File file = new File("yourfileName"); String path = file.getAbsolutePath();., Use: Paths.get(...).normalize().toString(). Another solution woul be: Paths.get(...).toAbsolutePath().toString(). However, you get strange results: Paths.get("/tmp", "foo").toString() returns /tmp/foo here. What is your filesystem?
相關軟體 Java Development Kit 資訊 | |
---|---|
![]() java get file path from string 相關參考資料
Create a Path from String in Java7 - Stack Overflow
Path p4 = FileSystems.getDefault().getPath("/tmp/foo"); Path p3 = Paths.get(URI.create("file:///Users/joe/FileTest.java")); Path p5 = Paths.get(System.getProperty("user.home&... https://stackoverflow.com file - Get the filePath from Filename using Java - Stack Overflow
Look at the methods in the java.io.File class: File file = new File("yourfileName"); String path = file.getAbsolutePath();. https://stackoverflow.com file - How to get the path string from a java.nio.Path? - Stack ...
Use: Paths.get(...).normalize().toString(). Another solution woul be: Paths.get(...).toAbsolutePath().toString(). However, you get strange results: Paths.get("/tmp", "foo").toStri... https://stackoverflow.com Get the directory from a file path in java (android) - Stack Overflow
A better way, use getParent() from File Class.. String a="/root/sdcard/Pictures/img0001.jpg"; // A valid file path File file = new File(a); String getDirectoryPath = file.getParent(); // On... https://stackoverflow.com java - How do I get the file name from a String containing the ...
just use File.getName() File f = new File("C:--Hello--AnotherFolder--The File Name.PDF"); System.out.println(f.getName());. using String methods: File f = new File("C:--Hello--AnotherF... https://stackoverflow.com java - How do I get the file name from a String containing the Absolute ...
public static String getFileName(String filePath) if( filePath==null || filePath.length()==0 ) return ""; filePath = filePath.replaceAll("[/----]+", "/"); int len = fil... https://stackoverflow.com java - How to get just the parent directory name of a specific ...
File file = new File("C:/aaa/bbb/ccc/ddd/test.java"); File curentPath = new File(file.getParent()); //get current path "C:/aaa/bbb/ccc/ddd/" String currentFolder= currentPath.getN... https://stackoverflow.com java - How to split a file path to get the file name? - Stack Overflow
one another possibility: String lStr = "/storage/emulated/0/temp.jpg"; lStr = lStr.substring(lStr.lastIndexOf("/")); System.out.println(lStr);. https://stackoverflow.com url - Get file name from a file location in Java - Stack Overflow
new File(fileName).getName();. or int idx = fileName.replaceAll("----", "/").lastIndexOf("/"); return idx >= 0 ? fileName.substring(idx + 1) : fileName;. Notice that ... https://stackoverflow.com url - Java: Get URI from FilePath - Stack Overflow
From SAXLocalNameCount.java from https://jaxp.java.net: /** * Convert from a filename to a file URL. */ private static String convertToFileURL ( String filename ) // On JDK 1.2 and later, simplify t... https://stackoverflow.com |