⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filelocator.java

📁 Java/J2EE框架Jdon-Framework系统的Sample
💻 JAVA
字号:
package com.jdon.util;

import java.io.InputStream;
import java.net.URL;
import java.io.File;

public class FileLocator {

  public String getConfPathXmlFile(String filePathName){
     int i = filePathName.lastIndexOf(".xml");
     String name = filePathName.substring(0, i);
     name = name.replace('.', '/');
     name += ".xml";
     return getConfFile(name);
  }

  public InputStream getConfPathXmlStream(String filePathName){
     int i = filePathName.lastIndexOf(".xml");
     String name = filePathName.substring(0, i);
     name = name.replace('.', '/');
     name += ".xml";
     return getConfStream(name);
  }


  public String getConfFile(String fileName) {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    if (classLoader == null) {
      classLoader = getClass().getClassLoader();
    }
    URL confURL = classLoader.getResource(fileName);
    if (confURL == null)
      confURL = classLoader.getResource("META-INF/" + fileName);
    if (confURL == null) {

      System.err.println(" in classpath can't  locate file: " + fileName);
      return null;
    } else {
      File file1 = new File(confURL.getFile());
      if (file1.isFile()) {
        System.out.println(" locate file: " + confURL.getFile());
        return confURL.getFile();
      } else {
        System.err.println(" it is not a file: " + confURL.getFile());
        return null;
      }
    }
  }

  public InputStream getConfStream(String fileName) {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    if (classLoader == null) {
      classLoader = this.getClass().getClassLoader();
    }
    InputStream stream = classLoader.getResourceAsStream(fileName);
    if (stream == null)
      stream = classLoader.getResourceAsStream("META-INF/" + fileName);
    if (stream == null) {
      System.err.println("PropsUtil error: cann't find config file:-->" +
                         fileName);
    }
    return stream;
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -