- package javax.org.path;
- import java.math.BigDecimal;
-
-
-
-
-
-
-
- public class AccessFile {
- public static final long KB = 1024;
- public static final long MB = KB * KB;
- public static final long GB = KB * MB;
-
-
-
- public static String fileSize(long file) {
- if (file <= 0) {
- return "";
- } else if (file < MB) {
- BigDecimal b = new BigDecimal((double) file / KB);
- return b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "K";
- } else if (file < GB) {
- BigDecimal b = new BigDecimal((double) file / MB);
- return b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "M";
- } else {
- BigDecimal b = new BigDecimal((double) file / GB);
- return b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "G";
- }
- }
-
-
-
- public static String getSysPath() {
-
- String path = Thread.currentThread().getContextClassLoader().getResource(".").toString();
- String temp = path.replaceFirst("file:/", "").replaceFirst("WEB-INF/classes/", "");
- String separator = System.getProperty("file.separator");
- String resultPath = temp.replaceAll("/", separator + separator);
- return resultPath;
- }
-
-
-
-
-
-
-
-
- public static String getClassPath() {
-
-
- String path = Thread.currentThread().getContextClassLoader().getResource("/").toString();
- String temp = path.replaceFirst("file:/", "");
- String separator = System.getProperty("file.separator");
- String resultPath = temp.replaceAll("/", separator + separator);
- return resultPath;
- }
-
-
-
-
-
-
-
- private String getClassesAbsolutePath(){
-
- String path=this.getClass().getClassLoader().getResource("").getPath();
-
-
- String temp = path.replaceFirst("/", "");
- String separator = System.getProperty("file.separator");
- String resultPath = temp.replaceAll("/", separator + separator);
- return resultPath;
- }
-
-
-
-
-
-
-
- private String getCurrentClassPath(){
-
-
- String path=this.getClass().getResource("/").getPath();
- String temp = path.replaceFirst("/", "");
- String separator = System.getProperty("file.separator");
- String resultPath = temp.replaceAll("/", separator + separator);
- return resultPath;
- }
- public static void main(String[] args) {
- System.out.println(getSysPath());
- }
- }
posted @
2013-06-19 11:47
最初的天堂
阅读(
289)
评论()
编辑
收藏
举报