久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <small id='vZLEK'></small><noframes id='vZLEK'>

    <tfoot id='vZLEK'></tfoot>

    1. <legend id='vZLEK'><style id='vZLEK'><dir id='vZLEK'><q id='vZLEK'></q></dir></style></legend>
        <bdo id='vZLEK'></bdo><ul id='vZLEK'></ul>

      <i id='vZLEK'><tr id='vZLEK'><dt id='vZLEK'><q id='vZLEK'><span id='vZLEK'><b id='vZLEK'><form id='vZLEK'><ins id='vZLEK'></ins><ul id='vZLEK'></ul><sub id='vZLEK'></sub></form><legend id='vZLEK'></legend><bdo id='vZLEK'><pre id='vZLEK'><center id='vZLEK'></center></pre></bdo></b><th id='vZLEK'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vZLEK'><tfoot id='vZLEK'></tfoot><dl id='vZLEK'><fieldset id='vZLEK'></fieldset></dl></div>
      1. 將文件大小格式化為 MB、GB 等

        Format file size as MB, GB, etc(將文件大小格式化為 MB、GB 等)

          <i id='0pyHo'><tr id='0pyHo'><dt id='0pyHo'><q id='0pyHo'><span id='0pyHo'><b id='0pyHo'><form id='0pyHo'><ins id='0pyHo'></ins><ul id='0pyHo'></ul><sub id='0pyHo'></sub></form><legend id='0pyHo'></legend><bdo id='0pyHo'><pre id='0pyHo'><center id='0pyHo'></center></pre></bdo></b><th id='0pyHo'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='0pyHo'><tfoot id='0pyHo'></tfoot><dl id='0pyHo'><fieldset id='0pyHo'></fieldset></dl></div>

          <small id='0pyHo'></small><noframes id='0pyHo'>

          • <bdo id='0pyHo'></bdo><ul id='0pyHo'></ul>
                <tbody id='0pyHo'></tbody>
              <legend id='0pyHo'><style id='0pyHo'><dir id='0pyHo'><q id='0pyHo'></q></dir></style></legend>
              <tfoot id='0pyHo'></tfoot>
                  本文介紹了將文件大小格式化為 MB、GB 等的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我需要使用合理的單位將文件大小顯示為字符串.

                  例如,

                  1L ==>1B";1024L ==>1 KB";2537253L ==>2.3 MB"

                  等等

                  我發現 this previous answer,我覺得不滿意.

                  我想出了自己的解決方案,但也有類似的缺點:

                  private static final long K = 1024;私有靜態最終長 M = K * K;私有靜態最終長 G = M * K;私有靜態最終長 T = G * K;public static String convertToStringRepresentation(final long value){最終的 long[] 分隔符 = new long[] { T, G, M, K, 1 };final String[] units = new String[] { TB"、GB"、MB"、KB"、B"};如果(值 <1)throw new IllegalArgumentException("無效的文件大小:"+ value);字符串結果 = null;for(int i = 0; i 

                  主要問題是我對 Decimalformat 和/或 String.format 的了解有限.我希望 1024L、1025L 等映射到 1 KB 而不是 1.0 KB.

                  所以,有兩種可能:

                  1. 我更喜歡公共圖書館中的開箱即用解決方案,例如 Apache Commons 或 Google Guava.
                  2. 如果沒有,我怎樣才能擺脫 '.0' 部分(不求助于字符串替換和正則表達式,我可以自己做)?

                  解決方案

                  public static String readableFileSize(long size) {如果(大小 <= 0)返回0";最終字符串 [] 單位 = 新字符串 [] { "B", "kB", "MB", "GB", "TB" };int digitGroups = (int) (Math.log10(size)/Math.log10(1024));return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups)) + " " + units[digitGroups];}

                  這將工作到 1000 TB....而且程序很短!

                  I need to display a file size as a string using sensible units.

                  For example,

                  1L ==> "1 B";
                  1024L ==> "1 KB";
                  2537253L ==> "2.3 MB"
                  

                  etc.

                  I found this previous answer, which I didn't find satisfactory.

                  I have come up with my own solution which has similar shortcomings:

                  private static final long K = 1024;
                  private static final long M = K * K;
                  private static final long G = M * K;
                  private static final long T = G * K;
                  
                  public static String convertToStringRepresentation(final long value){
                      final long[] dividers = new long[] { T, G, M, K, 1 };
                      final String[] units = new String[] { "TB", "GB", "MB", "KB", "B" };
                      if(value < 1)
                          throw new IllegalArgumentException("Invalid file size: " + value);
                      String result = null;
                      for(int i = 0; i < dividers.length; i++){
                          final long divider = dividers[i];
                          if(value >= divider){
                              result = format(value, divider, units[i]);
                              break;
                          }
                      }
                      return result;
                  }
                  
                  private static String format(final long value,
                      final long divider,
                      final String unit){
                      final double result =
                          divider > 1 ? (double) value / (double) divider : (double) value;
                      return String.format("%.1f %s", Double.valueOf(result), unit);
                  }
                  

                  The main problem is my limited knowledge of Decimalformat and / or String.format. I would like 1024L, 1025L, etc. to map to 1 KB rather than 1.0 KB.

                  So, two possibilities:

                  1. I would prefer a good out-of-the-box solution in a public library like Apache Commons or Google Guava.
                  2. If there isn't, how can I get rid of the '.0' part (without resorting to string replacement and regex, I can do that myself)?

                  解決方案

                  public static String readableFileSize(long size) {
                      if(size <= 0) return "0";
                      final String[] units = new String[] { "B", "kB", "MB", "GB", "TB" };
                      int digitGroups = (int) (Math.log10(size)/Math.log10(1024));
                      return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups)) + " " + units[digitGroups];
                  }
                  

                  This will work up to 1000 TB.... and the program is short!

                  這篇關于將文件大小格式化為 MB、GB 等的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)
                  <i id='zGQgR'><tr id='zGQgR'><dt id='zGQgR'><q id='zGQgR'><span id='zGQgR'><b id='zGQgR'><form id='zGQgR'><ins id='zGQgR'></ins><ul id='zGQgR'></ul><sub id='zGQgR'></sub></form><legend id='zGQgR'></legend><bdo id='zGQgR'><pre id='zGQgR'><center id='zGQgR'></center></pre></bdo></b><th id='zGQgR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='zGQgR'><tfoot id='zGQgR'></tfoot><dl id='zGQgR'><fieldset id='zGQgR'></fieldset></dl></div>
                  <legend id='zGQgR'><style id='zGQgR'><dir id='zGQgR'><q id='zGQgR'></q></dir></style></legend>

                • <small id='zGQgR'></small><noframes id='zGQgR'>

                      <tbody id='zGQgR'></tbody>

                          • <bdo id='zGQgR'></bdo><ul id='zGQgR'></ul>
                          • <tfoot id='zGQgR'></tfoot>
                            主站蜘蛛池模板: 欧洲精品在线观看 | a网站在线观看 | 欧美成人一区二区 | 亚洲精品欧美一区二区三区 | 欧美激情欧美激情在线五月 | 超碰精品在线观看 | www日本在线 | 亚洲国产精品久久久久秋霞不卡 | 毛片免费观看 | 成人精品一区二区三区 | 黄色网址在线免费观看 | 999久久 | 国产精品高清在线 | 国产伦一区二区三区久久 | 亚洲国产成人精品女人久久久 | 一区二区三区四区免费视频 | 亚洲欧美第一视频 | av一二三区| 国产午夜久久 | 超碰免费在线观看 | 久久中文字幕一区 | 亚洲h视频 | 激情一区二区三区 | 国产精品自产拍在线观看蜜 | 亚洲综合国产 | 国产精品五区 | 欧美三级视频 | 一区二区三区视频免费看 | 成人h视频在线观看 | 91久久久久久久久久久 | 国产一区二区三区在线 | 久久久久久91 | 欧美日韩一区不卡 | 日韩视频―中文字幕 | 日韩在线免费视频 | 久久一区视频 | 久久久久国产一区二区三区 | 亚洲国产伊人 | 欧美性久久 | 在线不卡视频 | 精品久久久久久久久久久久久久 |