Java Format for file sizes?
January 16, 2006 10:21 AM   Subscribe

Are there any Java Format classes for handling file sizes?

This weekend I was doing some Servlet/JSP programming when I caught the l10n bug. I suddenly realized that using the NumberFormat class I can print out "$10.40" for US viewers, "10,40 USD" for French, etc. Awesome, I tought, so I went around and changed other code to do the same (DateFormat et al.).

But I'm stuck with my file size code. I'd like to show "938.4 MB" for US viewers, "938,4 Mo" for French, etc but it doesn't look like Java comes with a class built in. My searches on Google and GNU.org have also yielded nothing.

Given time I could probably write the code on my own. But it seems like a common enough task that someone would have already done it... any help?
posted by sbutler to Computers & Internet (5 answers total)
 
Seems like you might be able to something funky with "java.text.DecimalFormat" or "java.text.ChoiceFormat", then just come up with a big 2d matrix of all the languages and all the postfixes.
posted by delmoi at 10:29 AM on January 16, 2006


Sounds like a job for resource bundles.
posted by furtive at 11:36 AM on January 16, 2006


Best answer: hmm. seems that jsr 108 was withdrawn and jsr 275 is not yet running. a java search for the person in charge of the second (who also appears in the first) doesn't turn up anything either. wait a year or two...
posted by andrew cooke at 12:40 PM on January 16, 2006


If you're doing display in a JSP, could you just use the JSTL format taglib? It's i18n aware.
posted by freshgroundpepper at 1:57 PM on January 16, 2006


i think that just calls the underlying format classes, so it has the same problem.
posted by andrew cooke at 2:24 PM on January 16, 2006


« Older Good used auto dealership in LA?   |   Location of no.6's flat? Newer »
This thread is closed to new comments.