<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
- /**
- *
- * @param path
- * @return
- */
- public static String toJavaFilePath(String path) {
- String FILE_SEPERATOR = "/";
- if (path == null) {
- return null;
- }
- path = StringUtils.replace(path, "//", FILE_SEPERATOR);
- path = StringUtils.replace(path, "////", FILE_SEPERATOR);
- path = StringUtils.replace(path, "//////", FILE_SEPERATOR);
- path = StringUtils.replace(path, "////////", FILE_SEPERATOR);
- path = StringUtils.replace(path, "/", FILE_SEPERATOR);
- path = StringUtils.replace(path, "//", FILE_SEPERATOR);
- path = StringUtils.replace(path, "///", FILE_SEPERATOR);
- path = StringUtils.replace(path, "////", FILE_SEPERATOR);
- path = StringUtils.replace(path, "${FILE_SEPERATOR}", FILE_SEPERATOR);
- return path;
- }
- /**
- *
- * @param path
- * @return
- */
- public static String toWebFilePath(String path) {
- if (path == null) {
- return null;
- }
- path = StringUtils.replace(path, "//", "/");
- path = StringUtils.replace(path, "////", "/");
- path = StringUtils.replace(path, "//////", "/");
- path = StringUtils.replace(path, "////////", "/");
- path = StringUtils.replace(path, "//", "/");
- path = StringUtils.replace(path, "///", "/");
- path = StringUtils.replace(path, "////", "/");
- path = StringUtils.replace(path, "${FILE_SEPERATOR}", "/");
- return path;
- }
本文介绍了一种用于规范化Java和Web文件路径的方法。通过替换多余的斜杠,确保了路径字符串的一致性和正确性,这对于文件系统的操作和Web应用的URL处理至关重要。
227

被折叠的 条评论
为什么被折叠?



