java读取配置文件

    技术2023-07-05  121

    java读取配置文件类

    java读取配置文件1、读取src目录下的文件2、读取src同级目录下的文件

    java读取配置文件

    1、读取src目录下的文件

    // An highlighted block Properties properties = new Properties(); // 此方法仅支持在src目录下配置文件的读取 InputStream inputStream = InfoUtils.class.getResourceAsStream("/info.properties"); try { properties.load(inputStream); } catch (IOException e) { e.printStackTrace(); }

    2、读取src同级目录下的文件

    Properties properties = new Properties(); try { // 可读取src同级目录下的配置文件 // 注意FileInputStream需要在try catch内 InputStream inputStream = new BufferedInputStream(new FileInputStream("resources/info.properties")); properties.load(inputStream); } catch (IOException e) { e.printStackTrace(); }

    写完收工,嘀嘀嘀

    Processed: 0.013, SQL: 9