Re: StringTokenizer() with "\" character



Lew wrote:
snehapshinde@xxxxxxxxx wrote:
String filename="C:\Program Files\Apache Software Foundation\Tomcat
5.5\webapps\upload\multipartform.htm";

You need to double the backslashes.

StringTokenizer st=new StringTokenizer(filename,"\",false);
String v="";
while(st.hasMoreTokens())
{
v=st.nextToken();
}
out.print(" filename is "+v+" this");

This piece of code is throwing following exception-
An error occurred at line: 3 in the jsp file: /Save.jsp
Generated servlet error:
String literal is not properly closed by a double-quote

But if i replace "\" with ".", then it is working fine,
What is the problem with "\"?
Plz [sic] Help!

The problem was programmer error.

<http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.10.6>
It is a compile-time error if the character following a backslash in an escape is not an ASCII b, t, n, f, r, ", ', \, 0, 1, 2, 3, 4, 5, 6, or 7.

Which includes ". The error was a missing quote, as stated. Inside a quoted string, the quoting character must be escaped. Thus "\"" is a string consisting of one ".
.



Relevant Pages

  • Re: Identifier expected error.
    ... return a String. ... do as Lew suggests and read the tutorials. ... University of Leicester, Leicester, LE1 7RH, UK ...
    (comp.lang.java.help)
  • Re: Backing Up Objects
    ... Lew wrote: ... of "String" would be valid. ... refuse to believe the OP was that stupid. ...
    (comp.lang.java.programmer)
  • Re: [parsing text file]Problem with a line with only ","
    ... Lew as a matter of fact after sending the massage I realized that I had to ... as the first test being done for example with a line like "," would lead not ... ok you think contextwise it is useless to add String and Value in a variable ...
    (comp.lang.java.help)
  • Re: References and comparisons
    ... Lew wrote: ... So you're saying someone can call themself a Java programmer and not even know "by heart" how to use primitive types and String? ...
    (comp.lang.java.help)
  • Re: Speeding up matching Strings in a set
    ... and you wanted to know if String x was ... Lew wrote: ... into a HashSet is O, which I predict no regex-based comparison will ... Here's where I see the trie approach losing to HashSet, ...
    (comp.lang.java.programmer)