java根据windows或者linux获取resources目录下的路径

        String filePath = null;
        String os = System.getProperty("os.name");
        if (os != null && os.toLowerCase().startsWith("windows")) {
             filePath = System.getProperty("user.dir") + File.separator + "src"+ File.separator+"main"+ File.separator+"resources" + File.separator + fileName;
        } else if (os != null && os.toLowerCase().startsWith("linux")) {
            filePath = RSATool.class.getClassLoader().getResource("").getPath() + fileName;
        }

  

原文地址:https://www.cnblogs.com/achengmu/p/13962632.html