Results 1 to 3 of 3
Thread: how to know the number of bytes
- 07-30-2007, 03:21 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 41
- Rep Power
- 0
- 07-30-2007, 06:35 PM #2
Senior Member
- Join Date
- Jul 2007
- Posts
- 135
- Rep Power
- 0
This is a more complicated question then it appears. What are you using the value for? The reason is that a Java String object is stored internally as unicode.
You can get the number of bytes by doing the following:
String str = "My name";
int bytes = str.getBytes().length;
But this number depends on the character encoding of my current platform.
There is also the length() method on the String class that will tell you the number of characters in the string.
- 08-06-2007, 06:13 PM #3
Member
- Join Date
- Jul 2007
- Posts
- 41
- Rep Power
- 0
Similar Threads
-
DES algorithm (Read and Write bytes to file)
By JoaoPe in forum Advanced JavaReplies: 6Last Post: 07-29-2008, 04:46 PM -
The highest number
By I-Shine in forum Java AppletsReplies: 3Last Post: 02-13-2008, 06:05 AM -
Reading bytes from InputStream
By Java Tip in forum Java TipReplies: 0Last Post: 11-25-2007, 08:51 PM -
How to get next available number from MS access
By shahjehan in forum JDBCReplies: 3Last Post: 11-18-2007, 08:41 PM -
how to know the number of the line
By simon in forum New To JavaReplies: 3Last Post: 08-01-2007, 05:59 PM
Bookmarks