Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to count bytes number in a string?

807605Sep 4 2007 — edited Sep 4 2007
I know it could seem a trivial question, nevertheless in my opinion it doesn't.

My problem is to check fileName lenght (before the file it is created) and throw an exception when the lenght is greater than the maximum lenght allowed for the current file system .

For example, in Linux (file system ext3) the maximum filename size is 255 bytes.

The lenght() method of String class returns the number of 16-bit unicode characters in the string.

In your opinion my check should be:
if (fileName.lenght() > 255 ....
or
if (fileName.lenght() > 255/2 ....
Thanks in advance, best regards.
Raffaele
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 2 2007
Added on Sep 4 2007
4 comments
542 views