如何高效操作Properties实现代码优化与性能提升?

2026-04-16 14:2512阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计118个文字,预计阅读时间需要1分钟。

如何高效操作Properties实现代码优化与性能提升?

读取resources目录下的properties文件作为properties对象:

javapublic static Properties loadProps(String fileName) { Properties props=null; InputStream is=null; try { is=Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); props=new Properties(); props.load(is); } catch (IOException e) { e.printStackTrace(); } finally { if (is !=null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } } return props;}

读取resources目录下的properties文件为properties对象

public static Properties loadProps(String fileName) { Properties props = null; InputStream is = null; try { is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); if (is == null) { throw new ClassNotFoundException(fileName + " file is not found"); } props = new Properties(); props.load(is); } catch (ClassNotFoundException | IOException e) { e.printStackTrace(); } finally { if (is != null){ try { is.close(); }catch (IOException e){ LOGGER.error("close input stream failure", e); } } } return props; }

如何高效操作Properties实现代码优化与性能提升?

本文共计118个文字,预计阅读时间需要1分钟。

如何高效操作Properties实现代码优化与性能提升?

读取resources目录下的properties文件作为properties对象:

javapublic static Properties loadProps(String fileName) { Properties props=null; InputStream is=null; try { is=Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); props=new Properties(); props.load(is); } catch (IOException e) { e.printStackTrace(); } finally { if (is !=null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } } return props;}

读取resources目录下的properties文件为properties对象

public static Properties loadProps(String fileName) { Properties props = null; InputStream is = null; try { is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); if (is == null) { throw new ClassNotFoundException(fileName + " file is not found"); } props = new Properties(); props.load(is); } catch (ClassNotFoundException | IOException e) { e.printStackTrace(); } finally { if (is != null){ try { is.close(); }catch (IOException e){ LOGGER.error("close input stream failure", e); } } } return props; }

如何高效操作Properties实现代码优化与性能提升?