-
java 文件处理
- 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());
- }
- }
-
相关阅读:
C语言基础二
while 循环 实例
Java学习笔记——设计模式之十.观察者模式
Java学习笔记——设计模式之九.建造者模式
Java学习笔记——设计模式之八.外观模式
spring定时任务详解(@Scheduled注解)
Eclipse中Java build path的使用
Nginx之(一)Nginx是什么
冒泡和随机排序
一段关于获取随机数的代码
-
原文地址:https://www.cnblogs.com/win7xt/p/3143882.html
Copyright © 2020-2023
润新知