Java??Jar???????????
???????????? ???????[ 2013/2/1 9:59:12 ] ????????
???????????ЩJar??????????????????????????????????????£?????????
????·????????????????????
/**
* ??·?????????????????????????
*
* @author lihzh
* @data 2012-4-11 ????9:33:44
*/
@Test
public void testGetFileFromAbsolutePath() {
String dirPathNotUnderClasspath = "D:\workspace-home\JavaDemo\conf";
File dirFile = new File(dirPathNotUnderClasspath);
AssertDirFile(dirFile);
}
/**
* ???????????????????
*
* @param dirFile
* @author lihzh
* @data 2012-4-11 ????9:49:14
*/
private void AssertDirFile(File dirFile) {
// ???????
Assert.assertTrue(dirFile.exists());
// ??·??
Assert.assertTrue(dirFile.isAbsolute());
// ????????
Assert.assertTrue(dirFile.isDirectory());
// ?????????????????
File[] files = dirFile.listFiles();
// ?????????
Assert.assertNotNull(files);
// ????????
Assert.assertEquals(1?? files.length);
// ????????
Assert.assertEquals("test.properties"?? files[0].getName());
}
???????????б???????·?????????
/**
* ?????·??????????????????·??????Eclipse?м??????????????? ???????? * ??·???????
*
* @author lihzh
* @data 2012-4-11 ????9:51:10
*/
@Test
public void testGetFileFromRelativePath() {
String dirPath = System.getProperty("user.dir") + "\conf";
File dirFile = new File(dirPath);
AssertDirFile(dirFile);
}
??????URI????????????
/**
* ????URI/URL????????·??????????????
*
* @author lihzh
* @throws URISyntaxException
* @throws MalformedURLException
* @data 2012-4-11 ????10:25:00
*/
@Test
public void testGetFileFromURIPath() throws URISyntaxException??
MalformedURLException {
// ?????URI???? ????URI??URL????????????????URL?????URL.toURI?????URI????
URI uri = new URI("file:/D:/workspace-home/JavaDemo/conf/");
File dirFile = new File(uri);
AssertDirFile(dirFile);
}
??????????????URI/URL????????·??????????????????????Щ·??????????????磺Spring???URI/URL?????·????????д??????????λ??λ???????????·????????Classpath??FileSystem????????????????£????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11