URL parentURL = new URL("file:/L:/WRK/toto/test/resources"); String path = FileUtilities.getAbsolutePath(parentURL, "myFile.xml"); // path will be "L:\WRK\toto\test\resources\myFile.xml" on Windows URL parentURL = new URL("file:/L:/WRK/my/files"); String path = FileUtilities.getAbsolutePath(parentURL, "L:/WRK/toto/test/resources/myFile.xml"); // path will be "L:\WRK\toto\test\resources\myFile.xml" on Windows
..
and .
) from a path and return the associated URL.URL url = FileUtilities.makeAbsoluteURLPath("L:/WRK/Java/resources/MyFile.xml"); // url will be "file:L:/WRK/Java/resources/MyFile.xml" url = FileUtilities.makeAbsoluteURLPath("L:/WRK/Java/resources/../MyFile.xml"); // url will be "file:L:/WRK/Java/MyFile.xml" url = FileUtilities.makeAbsoluteURLPath("L:/WRK/Java/resources/./MyFile.xml"); // url will be "file:L:/WRK/Java/resources/MyFile.xml"
OPTION_FILEEXIST_SKIP_QUERIES
or OPTION_FILEEXIST_SKIP_PHP
options are set, then the URL will still be considered as not existing even if the OPTION_FILEEXIST_HTTP_FORCETRUE
is setint option = FileUtilities.OPTION_FILEEXIST_SKIP_QUERIES + OPTION_FILEEXIST_SKIP_PHP; boolean exists = FileUtilities.exist(theUrl);Will check if the URL exist, but will consider that the URL does not exist if:
File dir = new File("C:/my/directory"); File theFile = FileUtilities.getFile("C:/thedirectory/myfile.txt"); // will return the File C:/thedirectory/myfile.txt File theFile2 = FileUtilities.getFile("myfile.txt"); // will return the File C:/my/directory/myfile.txt
zipfile.zip - directchild.txt - directory - file1.txtTo get the URL for the
directchild.txt
entry, we can do:File zipFile = new File("zipfile.zip"); URL url = zipFile.toURI().toURL(); URL childURL = FileUtilities.getJarEntryURL(url, "directchild.txt");To get the URL for the
file1.txt
entry, we can do:File zipFile = new File("zipfile.zip"); URL url = zipFile.toURI().toURL(); URL childURL = FileUtilities.getJarEntryURL(url, "directory/file1.txt");
File txtfile = new File("C:/my/file.txt"); File resulttxt = FileUtilities.getCompatibleFile(txtfile, "txt"); // will return the same C:/my/file.txt file resulttxt = FileUtilities.getCompatibleFile(txtfile, "png"); // will return the C:/my/file.png file txtfile = new File("C:/my/file.TXT"); File resulttxt = FileUtilities.getCompatibleFile(txtfile, "txt"); // will return the same C:/my/file.TXT file File file = new File("C:/my/thefile"); File resultjpg = FileUtilities.getCompatibleFile(txtfile, "jpg"); // will return the C:/my/file.jpg file
Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences