Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What's the maximum length of a string?

 
Mark Lau
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to implement a simple e-mail sender application using Java Mail.
Suppose I am going to make it a web-based application implemented in servlet.
Suppose the web interface has a message text box, in which the user can
enter the e-mail message.
Now here is my question: Suppose the user types in a lengthy text message of size 5K bytes. I am assuming that this size is good enough for my
question. How do I grab such a lengthy text? Can I use String? Like this:
String msg=request.getParameter("emailMessage");
I doubt this will work.
I guess I can do it using BufferedReader, like so:
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
But, the problem is how can I send the message in the buffer by e-mail?
Thanks a lot.
[ April 01, 2002: Message edited by: Gene Chao ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean "How long is a piece of String?"
Sorry, I couldn't resist
Dave
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might as well just go for the string.
A string can be pretty big. They're basically just over-glorified char[]'s. Since an array's size is of the type int, I'm guessing the maximum size of String is 2,147,483,647 characters. That should be enough to hold 5,000 characters with room to spare.
With the POST http method, a large amount of information can be sent without much trouble. You can upload much bigger files with the good old file upload forms.
String won't be the most efficient method, but I'll get the job done.
[ April 01, 2002: Message edited by: David Weitzman ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic