I have a string and from this string, I want to get password file path which is identified by an option (-sn).
String s = "msqlsum81pv 0 0 25 25 25 2 -sn D:\workdir\PV_81\config\sum81pv.pwf -C 5000"
above line is a configuration line which can be with either -sn
or -n
.
please suggest how to get D:\workdir\PV_81\config\sum81pv.pwf
line from above string or the string may be with quoted string.
below is my code which check only -sn option but I want to check with either -sn or -n .
if ( s.matches( "^\\s*msql.*$" ) )
{
StringTokenizer st = new StringTokenizer( s, " " );
while ( st.hasMoreTokens() )
{
if ( st.nextToken().equals( "-sn" ) )
{
pwf = st.nextToken();
}
}
}
I want to use StreamTokenizer instead of StringTokenizer class and get D:\workdir\PV_81\config\sum81pv.pwf
this path may be containing spaces in it.
String s = "msqlsum81pv 0 0 25 25 25 2 -sn D:\workdir\PV_81\config\sum81pv.pwf -C 5000"
if ( s.matches( "^\\s*msql.*$" ) )
{
StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(s));
while (tokenizer.nextToken() != StreamTokenizer.TT_EOF)
{
System.out.println(tokenizer.sval);
}
}