ITeye博客

Linux Classes 路径问题

hwpok · 2007-12-25 14:42 · Linux · Windows · OS · Linux · Web · Markdown

要得到web application中的classes路径可以使用如下方法:
    1.先查出是WINDOWS操作系统还是LINUX操作系统:

private boolean isWindows(){
        String operatorSystemName = System.getProperty("os.name");
        operatorSystemName = operatorSystemName.toUpperCase();
        if(operatorSystemName.indexOf("WIN")>0){
            return true;
        }
        return false;
    }

    2.得到classes路径:

String path = null;
path = this.getClass().getResource("/") + "Senders.txt";
path = path.substring(6,path.length());
if(!this.isWindows()){
    path += "/" + path;
}

    例外,在windows一般文本换行符为:"\r\n",而在liunx之中则为:"\n".

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。