包含inifilejava的词条

博主:adminadmin 2023-01-20 06:54:07 220

本篇文章给大家谈谈inifilejava,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

linux安装oracle静默建库时抛Exception in thread "main" java.lang.NullPointerException 求大神帮忙

java.lang.NullPointerException:这个提示是dbca抛出的java进程错误。

解决:

检查JDK安装路径和配置;

帮忙写个JAVA 读写ini配置文件小程序!!!!!

其实使用 JDK 里面提供的 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中如何设置读取ini配置文件?

// 读取一般的属性文件

FileInputStream fin=new FileInputStream("my.ini"); // 打开文件

Properties props=new Properties();                 // 建立属性类

props.load(fin);                                   // 读入文件

fin.close();                                       // 关闭文件

java 向ini配置文件中写入值。

Java读取和修改ini配置文件,参考如下:

/*

* ConfigurationFile.java

*

*/

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

/**

* 这是个配置文档操作类,用来读取和配置ini配置文档

* @author 由月

* @version 2004-08-18

* @修改 2008-05-22

*/

public final class ConfigurationFile {

/**

* 从ini配置文档中读取变量的值

* @param file 配置文档的路径

* @param section 要获取的变量所在段名称

* @param variable 要获取的变量名称

* @param defaultValue 变量名称不存在时的默认值

* @return 变量的值

* @throws IOException 抛出文档操作可能出现的io异常

*/

public static String getProfileString(

String file,

String section,

String variable,

String defaultValue)

throws IOException {

String strLine, value = "";

BufferedReader bufferedReader = new BufferedReader(new FileReader(file));

boolean isInSection = false;

try {

while ((strLine = bufferedReader.readLine()) != null) {

strLine = strLine.trim();

//strLine = strLine.split("[;]")[0];

Pattern p;

Matcher m;

p = Pattern.compile("\\["+section+"\\]");

m = p.matcher((strLine));

if (m.matches()) {

p = Pattern.compile("\\["+section+"\\]");

m = p.matcher(strLine);

if (m.matches()) {

isInSection = true;

} else {

isInSection = false;

}

}

if (isInSection == true) {

strLine = strLine.trim();

String[] strArray = strLine.split("=");

if (strArray.length == 1) {

value = strArray[0].trim();

if (value.equalsIgnoreCase(variable)) {

value = "";

return value;

}

} else if (strArray.length == 2) {

value = strArray[0].trim();

if (value.equalsIgnoreCase(variable)) {

value = strArray[1].trim();

return value;

}

} else if (strArray.length 2) {

value = strArray[0].trim();

if (value.equalsIgnoreCase(variable)) {

value = strLine.substring(strLine.indexOf("=") + 1).trim();

return value;

}

}

}

}

} finally {

bufferedReader.close();

}

return defaultValue;

}

inifilejava的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、inifilejava的信息别忘了在本站进行查找喔。