java项目使用ini(Java项目开发)

今天给各位分享java项目使用ini的知识,其中也会对Java项目开发进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

1、java.exe的使用格式2、java怎么通过读取ini文件来确定要输去文件的路径3、java 向ini配置文件中写入值。4、java读取ini文件导入到mysql数据库中5、Java中如何设置读取ini配置文件?6、帮忙写个JAVA 读写ini配置文件小程序!!!!!

java.exe的使用格式

将导出的.jar格式的文件制作成.exe格式的可执行的文件,(注意:此时的.exe文件只是可以执行,还不能够安装)。

1、在eclipse中创建java项目,然后编写Java代码,将编写好的Java项目导出一个.jar格式的jar包;2、通过安装exe4j软件,将导出的.jar格式的文件制作成.exe格式的可执行的文件,(注意:此时的.exe文件只是可以执行,还不能够安装);3、通过安装Inno setup软件,将可执行的.exe格式的文件、.jar格式的文件以及其它需要的文件制作成一个可安装的.exe格式的文件;

ini格式的配置文件最好是和项目(jar)包在一个工作目录下

java项目使用ini(Java项目开发)

java怎么通过读取ini文件来确定要输去文件的路径

import java.io.BufferedReader;

import java.io.File;

import java.io.FileInputStream;

import java.io.InputStreamReader;

public class IniFileReader 

{

    /**

     * 读取文件制定行

     * @param filePath 文件路径

     * @param key 文件中配置项的key 如:path = C:/aaa 中的”path = “(注意空格,以具体配置项为准)

     * @return String 制定的配置项的配置数据 如:path = C:/aaa 中的”C:/aaa”

     * @throws Exception

     */

    public static String readerSpcifyLine(String filePath,String key) throws Exception

    {

    StringBuffer result = new StringBuffer();

    

    FileInputStream fis = new FileInputStream(new File(filePath));

    BufferedReader reader = new BufferedReader(new InputStreamReader(fis));

    String line = “”;

    for(line = reader.readLine(); (line != null  !””.equals(line)); line = reader.readLine())

    {

    if(line.startsWith(key))

    {

    result.append(line.substring(line.indexOf(key) + key.length(), line.length()));

    break;

    }

    }

    fis.close();

    reader.close();

    return result.toString();

    }

    

    public static void main(String[] args) throws Exception

    {

    String filePath = “F:/document/path.ini”;

    String key = “path = “;

    String configFilePath = readerSpcifyLine(filePath,key);

    System.out.println(configFilePath);

    }

}

上面这个类应该能帮到你,上面有一个文件读取方法和一个main测试函数,可以读出你所说的配置项的信息,方法的说明看代码注释。

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;

}

java读取ini文件导入到mysql数据库中

用properties,先load那个.ini文件然后 迭代这个properties赋给jdbc里sql的占位符 然后执行语句就可以了,propertise是map的子类直接用keyset迭代就好了;

Java中如何设置读取ini配置文件?

// 读取一般的属性文件

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

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

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

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

帮忙写个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的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于Java项目开发、java项目使用ini的信息别忘了在本站进行查找喔。

本文来自投稿,不代表【】观点,发布者:【

本文地址: ,如若转载,请注明出处!

举报投诉邮箱:253000106@qq.com

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2024年3月31日 03:34:31
下一篇 2024年3月31日 03:42:46

相关推荐

  • 深入java虚拟机pdf,深入java虚拟机 中村成洋 pdf

    在linux环境下,java怎么实现从word格式转换为pdf格式 //设置当前使用的打印机,我的Adobe Distiller打印机名字为 Adobe PDF wordCom.setProperty( ActivePrinter , new Variant( Adobe PDF ));//设置printout的参数,将word文档打印为postscript…

    2024年5月23日
    3800
  • java截取指定长度字符串,java截取指定字符串之后的

    java中如何截取字符串中的指定一部分 第一个参数是开始截取的字符位置。(从0开始)第二个参数是结束字符的位置+1。(从0开始)indexof函数的作用是查找该字符串中的某个字的位置,并且返回。 int end);截取s中从begin开始至end结束时的字符串,并将其赋值给s;split讲解:java.lang.string.split split 方法 将…

    2024年5月23日
    3600
  • java绑定一个端口,java使用端口

    java如何多个service共用一个端口 你如果有多个项目的话,你可以把多个项目放到一个tomcat里面,这样端口相同使用项目名称来进行区分项目。你如果非要使用同一个,你也可以配置不同的域名导向不同的项目。就是访问的域名不同转接到的项目不同。 如果需要同时启动多个程序,要么修改tomcat的配置文件中的监听端口。要么修改jar包程序的监听端口。不能在一台服…

    2024年5月23日
    3000
  • java多线程并发编程基础,Java多线程并发执行返回

    电脑培训分享Java并发编程:核心理论 电脑培训发现本系列会从线程间协调的方式(wait、notify、notifyAll)、Synchronized及Volatile的本质入手,详细解释JDK为我们提供的每种并发工具和底层实现机制。 人们开始意识到了继承的众多缺点,开始努力用聚合代替继承。软件工程解决扩展性的重要原则就是抽象描述,直接使用的工具就是接口。接…

    2024年5月23日
    4100
  • 自学java找工作,自学java找工作需要包装简历吗

    自学java学多久可以找到工作 1、自学Java至少需要一年以上的时间才能达到找工作的水平。报班培训四到六个月的时间就可以找到一份不错的工作。 2、自学Java至少需要一年以上的时间才能达到找工作的水平。 3、如果要想找到一份Java相关的工作,需要至少学习5-6个月时间才能就业。Java开发需要掌握一些基础的编程语言知识,比如掌握面向对象的编程思想、基本的…

    2024年5月23日
    3800
  • java左移右移,java 左移

    java位移问题 1、思路:直接用Integer类的bit运算操作。 2、移位操作:左移:向左移位,符号后面的数字是移了多少位,移的位用0补齐,例如2进制数01111111左移一位后变为11111110,移位是字节操作。 3、Java 位运算 Java 位运算[转]一,Java 位运算表示方法: 在Java语言中,二进制数使用补码表示,最高位为符号位,正数的…

    2024年5月23日
    3700
  • java技术规范,java规范性要求

    现在主流的JAVA技术是什么? java最流行开发技术程序员必看 1 、Git Git一直是世界上最受欢迎的Java工具之一,也是Java开发人员最杰出的工具之一。Git是一个开源工具,是-种出色的分布式版本控制解决方案。 (1).Java基础语法、数组、类与对象、继承与多态、异常、范型、集合、流与文件、反射、枚举、自动装箱和注解。(2).Java面向对象编…

    2024年5月23日
    3500
  • javasocket编程,Java socket编程中,禁用nagle算法的参数

    Java进行并发多连接socket编程 1、Java可利用ServerSocket类对外部客户端提供多个socket接口。基本的做法是先创建一个ServerSocket实例,并绑定一个指定的端口,然后在这个实例上调用accept()方法等待客户端的连接请求。 2、Socket socket=server.accept(0;Thread handleThrea…

    2024年5月23日
    4100
  • java死亡,java死代码是什么意思

    我的世界传送回死亡点指令是什么? 1、下面就让我们一起来了解一下吧:我的世界回到死的地方的指令是输入/back,就可以回到死亡地点了,当然也可以看信标,因为死亡后会有一道光集中在死亡点,只要循着光就可以找到目的地了。 2、在服务器中的指令 首先打开指令台,在指令行输入“/back”就可以回到自己的死亡地点了。在单人游戏中的指令 在单人游戏中,您无法直接返回到…

    2024年5月23日
    4200
  • myeclipse能部署java工程么,myeclipse支持jdk18

    myeclipse如何建java文件 1、点击【File】—【New】–【Class】在如下界面,输入Class的名字,如Test,点击【Finish】。Test.java文件创建成功。 2、点击【File】—【New】–【Class】 在如下界面,输入Class的名字,如Test,点击【Finish】。 Te…

    2024年5月23日
    3500

发表回复

登录后才能评论



关注微信