| import com.sun.xml.internal.bind.v2.TODO; |
| |
| import java.io.File; |
| import java.io.FileInputStream; |
| import java.io.FileNotFoundException; |
| import java.io.FileOutputStream; |
| import java.io.IOException; |
| import java.io.InputStream; |
| import java.io.OutputStream; |
| import java.util.HashMap; |
| import java.util.Iterator; |
| import java.util.Map; |
| import java.util.Properties; |
| import java.util.Set; |
| |
| |
| public class PropertiesUtil { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public static String getProperties(String key) { |
| Properties prop = new Properties(); |
| InputStream url = PropertiesUtil.class.getResourceAsStream("/conf/deploy.properties"); |
| FileInputStream in = null; |
| try { |
| prop.load(url); |
| } catch (FileNotFoundException e1) { |
| e1.printStackTrace(); |
| } catch (IOException e) { |
| e.printStackTrace(); |
| } finally { |
| if (in != null) { |
| try { |
| in.close(); |
| in = null; |
| } catch (IOException e) { |
| e.printStackTrace(); |
| } |
| } |
| } |
| |
| |
| return (String) prop.get(key); |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| public static String getProperties(String path, String key) { |
| Properties prop = new Properties(); |
| InputStream url = null; |
| FileInputStream in = null; |
| try { |
| url = new FileInputStream(path); |
| } catch (FileNotFoundException e2) { |
| |
| e2.printStackTrace(); |
| } |
| |
| try { |
| prop.load(url); |
| } catch (FileNotFoundException e1) { |
| e1.printStackTrace(); |
| } catch (IOException e) { |
| e.printStackTrace(); |
| } finally { |
| if (in != null) { |
| try { |
| in.close(); |
| in = null; |
| } catch (IOException e) { |
| e.printStackTrace(); |
| } |
| } |
| } |
| |
| return (String) prop.get(key); |
| |
| } |
| |
| |
| |
| |
| |
| |
| public static void addProperties(String key, String value) { |
| |
| InputStream url = PropertiesUtil.class.getResourceAsStream("/conf/deploy.properties"); |
| Properties prop = new Properties(); |
| try { |
| prop.load(url); |
| } catch (IOException e) { |
| e.printStackTrace(); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| prop.put(key, value); |
| |
| |
| try { |
| OutputStream outputStream = new FileOutputStream(new File(PropertiesUtil.class.getResource("/conf/deploy.properties").getFile())); |
| prop.store(outputStream, null); |
| outputStream.flush(); |
| outputStream.close(); |
| System.out.println("添加成功"); |
| } catch (IOException e) { |
| e.printStackTrace(); |
| } |
| |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| public static void addProperties(String path, String key, String value) { |
| InputStream url = null; |
| try { |
| url = new FileInputStream(path); |
| } catch (FileNotFoundException e1) { |
| |
| e1.printStackTrace(); |
| } |
| Properties prop = new Properties(); |
| try { |
| prop.load(url); |
| } catch (IOException e) { |
| e.printStackTrace(); |
| } |
| |
| |
| Map toSaveMap = new HashMap(); |
| Set keys = prop.keySet(); |
| for (Iterator itr = keys.iterator(); itr.hasNext(); ) { |
| String oldKey = (String) itr.next(); |
| Object oldValue = prop.get(oldKey); |
| toSaveMap.put(oldKey, oldValue); |
| } |
| toSaveMap.put(key, value); |
| |
| prop.putAll(toSaveMap); |
| |
| System.out.println(toSaveMap.toString()); |
| |
| try { |
| OutputStream outputStream = new FileOutputStream(new File(path)); |
| prop.store(outputStream, null); |
| outputStream.flush(); |
| outputStream.close(); |
| System.out.println("添加成功"); |
| } catch (IOException e) { |
| e.printStackTrace(); |
| } |
| |
| |
| } |
| |
| |
| |
| |
| |
| |
| public static void updateProperties(String key, String value) { |
| InputStream url = PropertiesUtil.class.getResourceAsStream("/conf/deploy.properties"); |
| Properties prop = new Properties(); |
| try { |
| prop.load(url); |
| } catch (IOException e) { |
| e.printStackTrace(); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| prop.put(key, value); |
| |
| |
| try { |
| OutputStream outputStream = new FileOutputStream(new File(PropertiesUtil.class.getResource("/conf/deploy.properties").getFile())); |
| prop.store(outputStream, null); |
| outputStream.flush(); |
| outputStream.close(); |
| System.out.println("修改成功"); |
| } catch (IOException e) { |
| e.printStackTrace(); |
| } |
| |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| public static void updateProperties(String path, String key, String value) { |
| InputStream url = null; |
| try { |
| url = new FileInputStream(path); |
| } catch (FileNotFoundException e1) { |
| |
| e1.printStackTrace(); |
| } |
| Properties prop = new Properties(); |
| try { |
| prop.load(url); |
| } catch (IOException e) { |
| e.printStackTrace(); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| prop.put(key, value); |
| |
| |
| try { |
| OutputStream outputStream = new FileOutputStream(new File(path)); |
| prop.store(outputStream, null); |
| outputStream.flush(); |
| outputStream.close(); |
| System.out.println("修改成功"); |
| } catch (IOException e) { |
| e.printStackTrace(); |
| } |
| |
| |
| } |
| |
| |
| |
| |
| |
| public void delProperties(String key) { |
| |
| InputStream url = PropertiesUtil.class.getResourceAsStream("/conf/deploy.properties"); |
| Properties prop = new Properties(); |
| try { |
| prop.load(url); |
| } catch (IOException e) { |
| e.printStackTrace(); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| prop.remove(key); |
| |
| |
| try { |
| |
| FileOutputStream outputStream = new FileOutputStream(PropertiesUtil.class.getResource("/conf/deploy.properties").getFile()); |
| |
| prop.store(outputStream, null); |
| outputStream.flush(); |
| outputStream.close(); |
| |
| System.out.println("删除成功"); |
| } catch (IOException e) { |
| |
| e.printStackTrace(); |
| |
| } |
| |
| } |
| |
| |
| |
| |
| |
| |
| public void delProperties(String path, String key) { |
| |
| |
| InputStream url = null; |
| try { |
| url = new FileInputStream(path); |
| } catch (FileNotFoundException e1) { |
| |
| e1.printStackTrace(); |
| } |
| Properties prop = new Properties(); |
| try { |
| prop.load(url); |
| } catch (IOException e) { |
| e.printStackTrace(); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| prop.remove(key); |
| |
| |
| try { |
| |
| FileOutputStream outputStream = new FileOutputStream(path); |
| |
| prop.store(outputStream, null); |
| outputStream.flush(); |
| outputStream.close(); |
| |
| System.out.println("删除成功"); |
| } catch (IOException e) { |
| |
| e.printStackTrace(); |
| |
| } |
| |
| } |
| |
| } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)