「java读取(.ini)」java读取ini文件section对应的内容

博主:adminadmin 2022-12-30 13:15:09 865

本篇文章给大家谈谈java读取(.ini),以及java读取ini文件section对应的内容对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

请问怎么用java一行一行的读取ini文件,然后进行内容匹配,最后输出一个list? 已有的是一个

你好,你的问题是:如何在一个class里使用另一个class的应用。

先看你Parser类上方四行代码

package parseme;

import java.util.ArrayList;

import java.util.Calendar;

import java.io.*;

public class Parser {

    private static ArrayListPerson personen = new ArrayList();

    //...

}

Java里的关键字import,意思是导入类(无需后缀.class)。即你可以在导入某个类之后,按照规范调用该类的属性和行为。表现为:

import packageName.ClassName;

//如上述代码,Parser中定义了Person类的集合personen

packageName就是代码第一行的,称为“包名”,简单理解就是路径

package parseme;

Java规范允许同一包下的类在互相使用时无需显示导入类(另默认导入了java.lang路径下的所有类)。所以Parser类可以在代码中直接调用Person类。因为它们属于同一路径

package parseme;

//import ...

public class Person{

    //...

}

使用另一个类的应用(属性和行为),你可以看到Parser类中的parse方法

Person p = new Person(vname, nname, birthd);

//...

System.out.println(p);

//等等,均为你所说的使用另一个类的应用

类中成员表现形式有两种:类变量/方法和实例变量/方法

类变量通常用static关键词修饰,如

System.out.println(p);//System是java.lang包下的类,out是System中一个由static修饰过的变量(类变量),out本身是一个实例,它提供了实例方法println()。

实例变量只允许类的对象使用,如

Person p = new Person(vname, nname, birthd);//实例化Person、新建Person对象

//Person类中有许多没有static关键词修饰的变量和方法,只有实例化之后才可以使用它们。

p.toString();

帮忙写个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程序读取Windows目录下的win.ini文件,并打印输出其类容

win.ini

只是一个ini配置文件而已

以前98的时候是靠读取加栽win.ini来实现电脑的很多功能的

98后就没有这样了,但是却保留了win.ini的加栽

这个文件的具体功能如下:[Windows]:影响Windows操作环境的部分,包括在启动Windows时执行哪一个应用程序,警告声音的设置、窗口边框的宽度、键盘响应的速度、鼠标器设置以及将文件定义为文档或程序等。

[Desktop]:控制系统界面显示形式及窗口和鼠标器的位置。

[Extensions]:联结特定的文件类型与相应的应用程序。

[Intl]:描述怎样为除美国外的其它国家显示有关的文件项目。

[Windows Help]:列出有关HELP窗口及对话窗的默认尺寸、布局、文本颜色等设置。

[Font Substitue]:列出Windows可识别的互换字体。

[TureType]:使用和显示TrueType字体的可选设置。

[Sounds]:为每个系统事件设计的声音文件列表。

[MCI Extensions]:把MEDIA控制接口设备同特定文件类型联系起来。

[Compatibility]:用于解决Windows 98和Windows 3.x之间的差异所引起的兼容性问题。

[Compatibility32]:用于解决Windows 98和Windows 3.X之间的差异所引起的32位磁盘存取兼容性问题。

[MCI Compatibility]:用于Windows 98中文版的MCI设备兼容性问题。

[Module Compatibility]:用于Windows 98中文版的模块兼容性问题。

[IME Compatibility]:用于Windows 98中文版的输入法与应用程序的兼容性问题。

[Pscript.Drv]:描述PostScrip打印机的ATM字库状况。

[Fonts]:描述Windows装入的屏幕字体文件。

Embedding:列出目标联接与嵌入(OLE)使用的服务器目标。

[Colors]:定义Windows的显示颜色。

[PrinterPorts]:Windows将要访问的激活或非激活的输出设备。

[Ports]:描述中文Windows 98的可用端口。

[Mail]:描述Microsoft Mail以及Microsoft Exchange的使用参数。

[Devices]:与旧版本Windows的应用程序兼容的激活输出设备。

[Programs]:当用户打开多个数据文件时,该段可为Windows查找相应程序文件提供附加的路径。

[Associated CharSet]:描述Windows 98中文版使用字符集状态和西文字体所对应的缺省中文字体。

[Windows Telephony]:描述Windows 98中文版的Microsoft Exchange的电话号码初始化日期和时间。

[Paintbrush]:描述Windows 98中文版的“画图”(PaintBrush)的省略图片格式。

[MAPI 1.0 Time Zone]:描述MAPI 1.0的时区设置参数.

首先你需要明白你老师要你做什么

1。是需要你把win.ini在个文件的内容打印在纸上

2。还是读取win.ini文件的具体然后打印在纸上

如果是1。直接打印就好了,只要写一个调用打印机的东西就可以了

如果是2。那么现在基本可以忽略,你可以告诉你的老师

这道题目已经过时了,完全没有意义

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

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

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文件section对应的内容的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。