public static Hashtable parseQueryString(String s)
{
Object obj = null;
if(s == null)
throw new IllegalArgumentException();
Hashtable hashtable = new Hashtable();
StringBuffer stringbuffer = new StringBuffer();
String as[];
String s2;
for(StringTokenizer stringtokenizer = new StringTokenizer(s, "&"); stringtokenizer.hasMoreTokens(); hashtable.put(s2, as))
{
String s1 = stringtokenizer.nextToken();
int i = s1.indexOf(61);
if(i == -1)
throw new IllegalArgumentException();
s2 = parseName(s1.substring(0, i), stringbuffer);
String s3 = parseName(s1.substring(i + 1, s1.length()), stringbuffer);
if(hashtable.containsKey(s2))
{
String as1[] = (String[])hashtable.get(s2);
as = new String[as1.length + 1];
for(int j = 0; j < as1.length; j++)
as[j] = as1[j];
as[as1.length] = s3;
} else
{
as = new String[1];
as[0] = s3;
}
}
return hashtable;
}
这是servlet包中的HttpUtil的一个方法,其中
String s = "abcde&fgh61=klklkl";
System.out.println("s.indexOf(61):"+s.indexOf(61));
indexOf将会返回等号在字符串当中的位置。
2。
File file;
file = File.createTempFile("policy","pdf");
System.out.println(file.getName());
这个语句将会返回类似于policy%pdf的临时文件。第一个参数为文件名的前缀,第二个参数为文件名的后缀,第三个参数可以不指定(标记临时文件所在路径directory)
System.out.println(file.getAbsoluteFile());或者
System.out.println(file.getAbsolutePath());将 返回该临时文件所在的绝对路径:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\policy26872pdf
System.out.println(file.getCanonicalPath()); 将返回一个比较规则的表示字符串:
C:\Documents and Settings\Administrator\Local Settings\Temp\policy58766pdf
System.out.println(file.getParent());===》C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
System.out.println(file.toURI()); ===》 file:/C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/policy45597pdf
System.out.println(file.toURL());===》 file:/C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/policy45597pdf