首页 > 技术文章 > java 文件加载 windows 和linux下

adao21 2020-05-11 16:34 原文

xml文件和启动文件在同一包下:

 

 

    public static InputStream getOadXmlPath() throws FileNotFoundException {
        InputStream in = null;
        String fileName = "OADMapping.xml";
        String os = System.getProperty("os.name");
        if (os != null && os.toLowerCase().startsWith("windows")) {
            String filePath = System.getProperty("user.dir") + File.separator + "src/main/com/adao/dataprocess/"
                    + fileName;
            File file = new File(filePath);
            in = new FileInputStream(file);
        } else if (os != null && os.toLowerCase().startsWith("linux")) {
            in = Application.class.getResourceAsStream(fileName);
        }
        return in;
    }

 

推荐阅读