static函式塊中如何呼叫外部xml引數?

insky發表於2008-04-19

public class StopwordsEnglish extends Stopwords {   
       
    /**  
     *   
     */  
    private static final long serialVersionUID = 1L;   
       
       
    /** The hashtable containing the list of stopwords */  
    private static Hashtable m_Stopwords = null;   
       
       
    static {   
           
        if (m_Stopwords == null) {   
            m_Stopwords = new Hashtable();   
            Double dummy = new Double(0);   
            File txt = new File("data/stopwords/stopwords_en.txt");    
            InputStreamReader is;   
            String sw = null;   
            try {   
                is = new InputStreamReader(new FileInputStream(txt), "UTF-8");   
                BufferedReader br = new BufferedReader(is);                
                while ((sw=br.readLine()) != null)  {   
                    m_Stopwords.put(sw, dummy);      
                }   
            } catch (Exception e) {   
                e.printStackTrace();   
            }   
               
        }   
    }   
       
    /**   
     * Returns true if the given string is a stop word.  
     */  
    public boolean isStopword(String str) {   
           
        return m_Stopwords.containsKey(str.toLowerCase());   
    }   
}  
<p class="indent">


File txt = new File("data/stopwords/stopwords_en.txt"); 這句想傳一個引數進去(改下opwords_en.txt的路徑) 但是這段在一個static塊中,如果改成建構函式的形式需要該太多的相關呼叫類,這裡如果加段讀取外部xml配置檔案中的引數會不會不好? 大家給點意見如何修改最好 謝謝

相關文章