java程序中my.ini_帮忙写个JAVA 读写ini配置文件小程序!!!!!
展开全部
其实使用 JDK 里面提供的e68a843231313335323631343130323136353331333335306263 Properties 最方便。 相关使用方法可以自己去查看 JDK 的API文档。 package product;import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;public class IniReader {
private Properties properties = new Properties();
private String iniPath = "test/product/pro.ini"; //ini 文件的路径
private JFrame jFrame = new JFrame("读取配置示例");
private JLabel jLabel1 = new JLabel("用户登录IP");
private JTextField jTextField1 = new JTextField(30);
private JLabel jLabel2 = new JLabel("端口号");
private JTextField jTextField2 = new JTextField(30);
private JLabel jLabel3 = new JLabel("TQ终端IP");
private JTextField jTextField3 = new JTextField(30);
private JLabel jLabel4 = new JLabel("端口号");
private JTextField jTextField4 = new JTextField(30);
private JLabel jLabel5 = new JLabel("WM终端IP");
private JTextField jTextField5 = new JTextField(30);
private JLabel jLabel6 = new JLabel("端口号");
private JTextField jTextField6 = new JTextField(30);
private JButton jButton1 = new JButton("取消");
private JButton jButton2 = new JButton("确定");
private void showFrame(){
try {
File file = new File(iniPath);
System.out.println(file.getAbsolutePath());
properties.load(new FileInputStream(iniPath));
} catch (FileNotFoundException e) {
System.out.println("找不到该文件");
JOptionPane.showMessageDialog(null, "保存信息出错!");
return;
} catch (IOException e) {
System.out.println("文件读取错误");
JOptionPane.showMessageDialog(null, "保存信息出错!");
return;
}
jTextField1.setText(properties.getProperty("UserLogin"));
jTextField2.setText(properties.getProperty("Userport"));
jTextField3.setText(properties.getProperty("TQterminal"));
jTextField4.setText(properties.getProperty("TQport"));
jTextField5.setText(properties.getProperty("VMterminal"));
jTextField6.setText(properties.getProperty("VMport"));
jButton1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
jTextField1.setText(properties.getProperty("UserLogin"));
jTextField2.setText(properties.getProperty("Userport"));
jTextField3.setText(properties.getProperty("TQterminal"));
jTextField4.setText(properties.getProperty("TQport"));
jTextField5.setText(properties.getProperty("VMterminal"));
jTextField6.setText(properties.getProperty("VMport"));
}
});
jButton2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) {
properties.setProperty("UserLogin", jTextField1.getText());
properties.setProperty("Userport", jTextField2.getText());
properties.setProperty("TQterminal", jTextField3.getText());
properties.setProperty("TQport", jTextField4.getText());
properties.setProperty("VMterminal", jTextField5.getText());
properties.setProperty("VMport", jTextField6.getText());
try {
properties.store(new FileOutputStream(iniPath),"");
} catch (Exception e1) {
e1.printStackTrace();
System.out.println("保存信息出错");
JOptionPane.showMessageDialog(jFrame, "保存信息出错!");
}
JOptionPane.showMessageDialog(jFrame, "保存成功!");
}
});
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jLabel1.setBounds(10, 40, 80, 30);
jTextField1.setBounds(100, 40, 80, 30);
jLabel2.setBounds(210, 40, 80, 30);
jTextField2.setBounds(300, 40, 80, 30);
jLabel3.setBounds(10, 80, 80, 30);
jTextField3.setBounds(100, 80, 80, 30);
jLabel4.setBounds(210, 80, 80, 30);
jTextField4.setBounds(300, 80, 80, 30);
jLabel5.setBounds(10, 120, 80, 30);
jTextField5.setBounds(100, 120, 80, 30);
jLabel6.setBounds(210, 120, 80, 30);
jTextField6.setBounds(300, 120, 80, 30);
jFrame.getContentPane().setLayout(null);
jFrame.getContentPane().add(jLabel1);
jFrame.getContentPane().add(jLabel2);
jFrame.getContentPane().add(jLabel3);
jFrame.getContentPane().add(jLabel4);
jFrame.getContentPane().add(jLabel5);
jFrame.getContentPane().add(jLabel6);
jFrame.getContentPane().add(jTextField1);
jFrame.getContentPane().add(jTextField2);
jFrame.getContentPane().add(jTextField3);
jFrame.getContentPane().add(jTextField4);
jFrame.getContentPane().add(jTextField5);
jFrame.getContentPane().add(jTextField6);
jButton1.setBounds(100,160,60,30);
jButton2.setBounds(230,160,60,30);
jFrame.getContentPane().add(jButton1);
jFrame.getContentPane().add(jButton2);
jFrame.setBounds(200, 200, 400, 300);
jFrame.setVisible(true);
}
public static void main(String[] args) {
new IniReader().showFrame();
}}
经测试,可用,正常。就是文件路径你自己配好。
本回答由网友推荐
已赞过
已踩过<
你对这个回答的评价是?
评论
收起
java程序中my.ini_帮忙写个JAVA 读写ini配置文件小程序!!!!!相关推荐
- 微信小程序中的html路径,新媒体运营:如何提取微信小程序路径到指定页面
目前微信小程序的功能已经非常的完善,可能平时我们都没有留意到.现在很多的app都有小程序版本,在微信端使用及推广都很便捷. 新媒体运营的同学们可能会发现一个问题,就是怎么才能直接到达小程序的一个指定页 ...
- Java程序中使用Spire Jar包报java.lang.NoSuchMethodError类型错误的解决方法
Jar包功能概述 使用Spire系列的Jar包可以操作Word.Excel.PPT.PDF.Barcode等格式的文件,分别对应使用的jar包是Spire.Doc for Java.Spire.XLS ...
- Java后台微信点餐小程序开发最新版笔记,Springboot+Mysql+Freemarker+Bootstrap+微信小程序实现扫码点餐小程序,包含语音提示,微信消息推送,网页管理后台
由于之前的Java后台微信点餐小程序有些知识点过时了,所以今天重新出一版,把里面过时的知识点更新下 前五章是部署笔记,后面是知识点的详细讲解,大家可以先看部署笔记,部署起来后,再跟着详细知识学习. 第 ...
- python自动填写小程序表单_新年好!教大家用Python写一个自动回复拜年信息的小程序!...
原标题:新年好!教大家用Python写一个自动回复拜年信息的小程序! 过年期间,想必大家都收到很多拜年信息吧!有没有也被拜年短信(大部分是群发)搞得很焦虑?不回复似乎显得很没有礼貌,一一回复又累心劳神 ...
- java 线程中创建线程_如何在Java 8中创建线程安全的ConcurrentHashSet?
java 线程中创建线程 在JDK 8之前,还没有办法在Java中创建大型的线程安全的ConcurrentHashSet. java.util.concurrent包甚至没有一个名为Concurren ...
- 我给舅舅用Python写了一个订餐系统微信小程序!生意简直火爆!
微信登录功能的实现 通过小程序的前端 配合python-flask的后端,实现登录接口的功能 在我们正式写代码之前 读一下微信小程序的官方文档. https://developers.weixin.q ...
- java反编译微信小程序_教你如何一键反编译获取任何微信小程序源代码(图形化界面,傻瓜式操作)...
一键获取微信小程序源代码 1 Tips:2 一键获取微信小程序源码, 使用了C#加nodejs制作 直接解压在D盘根目录下后就可以使用 将小程序文件放到 wxapkg目录下 3 这个目录下有一些dem ...
- python加油代码_python入门教程NO.5 用python写个自动选择加油站的小程序
本文涉及的python基础语法为:if条件分支 Python条件分支是通过一条或者多条语句的执行结果True或者False来决定是否执行相应的代码块. if单向条件语法结构 if 判断条件: 代码块 ...
- Python入门教程NO.5 用python写个自动选择加油站的小程序
本文涉及的 python 基础语法为:if 条件分支 Python 条件分支是通过一条或者多条语句的执行结果 True或者 False来决定是否执行相应的代码块. if 单向条件语法结构 if 单向条 ...
最新文章
- LeetCode 11 Container With Most Water
- Spring框架中的设计模式(五)
- 鲜为人知的编程真相(转载)
- 看人家如何拿到腾讯阿里的offer
- WCF、WebAPI、WebService之间的区别
- 做开发,这几种锁机制你不得不了解一下
- SAP License:瞎搞!你真的懂什么是ERP、中台和低代码吗?
- python docs库_python库之_thread
- spark的UI界面解析
- 斯威夫特山地车_斯威夫特枚举
- 整理的C++面试,这些是最为常见的
- 写一简单kernel心得
- 我在阿里工作9年,今天我离职了
- git创建本地代码库
- VMware虚拟机不能识别U盘 的解决方法
- 英文文本分类——电影评论情感判别
- 服务器无法取消指令方块显示,我的世界服务器如何关掉命令方块的提示(如图)...
- GDB调试命令以及GDB调试段错误
- .NET/C# — EXCEL文件内容添加到数据库中
- 使用pdfcrack破解PDF密码(Linux)