parseQueryString等java片斷

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.