java get file path from string
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--AnotherFolder--The File Name.PDF"); System.out.println(f.g, Look at the methods in the java.io.File class: File file = new File("yourfileName"); String path = file.getAbsolutePath();., 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"),"logs", "foo.log");. In Wind, new File(fileName).getName();. or int idx = fileName.replaceAll("----", "/").lastIndexOf("/"); return idx >= 0 ? fileName.substring(idx + 1) : fileName;. Notice that the first solution is system dependent. It only takes t, 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.getName().toString(); //get name of file to string "dd, public static String getFileName(String filePath) if( filePath==null || filePath.length()==0 ) return ""; filePath = filePath.replaceAll("[/----]+", "/"); int len = filePath.length(), upCount = 0; while( len>0 ) //remov, one another possibility: String lStr = "/storage/emulated/0/temp.jpg"; lStr = lStr.substring(lStr.lastIndexOf("/")); System.out.println(lStr);., 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 this to: // "path = file.toURL().toString()". , 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(); // Only return path if physical file exist else return null., 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 Development Kit(也叫 JDK)是一個非常專業的跨平台的 SDK 平台,由 Oracle 公司定期提供支持。為了提供來自世界各地的 Java SE,Java EE 和 Java ME 平台的開發人員的具體實現。由於其強大的開發支持,該 SDK 包代表了最廣泛和最廣泛使用的 Java SDK 平台,用於創建各種規模的企業項目和開源項目。 Java Development Ki... Java Development Kit 軟體介紹
java get file path from string 相關參考資料
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 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 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 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 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 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 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 - 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 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 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 |