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