RFR: 8288882: JFileChooser - empty (0 bytes) file is displayed as 1 KB [v25]

Abhishek Kumar duke at openjdk.org
Fri Sep 2 11:37:02 UTC 2022


On Fri, 2 Sep 2022 00:46:39 GMT, Phil Race <prr at openjdk.org> wrote:

> AK > Since we are displaying file size in one decimal precision, files having size from 1 to 199 byte will be 0.1 KB.
> 
> PR > Yes, I see that. My point is it seems wrong.
> 
> AK > Can you please suggest me what should I do to handle 1 byte to199 bytes ?
> 
> PR : Just consistently round up
> 
>     * 0 bytes is 0 kb
> 
>     * 1-100 bytes is 0.1 kb
> 
>     * 101-199 bytes is 0.2 kb
> 
>     * 901 -1000 bytes is 1kb
>       and so on

The file size calculation logic has been changed to display the file size with round up value for < 1000 byte size. It will show similar values as mentioned here.
![Smaller_File_Size](https://user-images.githubusercontent.com/107542245/188130510-330ee330-a4c4-46ce-9f2a-cce880f4e264.png)



But the native file system in linux does the rounding off for file length >1000 bytes.
For example :
1250 bytes is displayed as 1.2 KB and 1251 bytes is displayed as 1.3 KB.

So to keep JFileChooser behavior similar to native file system, the existing logic has been changed to use DecimalFormat object for formatting file size.

It returns the file size similar to file managers on linux.

JFileChooser File Size:
![JFileChooser_File_Size1](https://user-images.githubusercontent.com/107542245/188130027-d43f70de-0501-4e61-900d-55f12525c35d.png)

Native System File Size:
![Native_File_System_Size](https://user-images.githubusercontent.com/107542245/188130137-78e4a82b-9edc-4103-b120-9f70bbecce58.png)

-------------

PR: https://git.openjdk.org/jdk/pull/9327



More information about the client-libs-dev mailing list