import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;
public class Testaa
{
public static void main(String[] args) {
String configpath = "D:\\initest.ini";
FileInputStream fis = null; // 读
OutputStream fos;
Properties pp;
// 初始化并加载读取的文件
try {
pp = new Properties();
fis = new FileInputStream(configpath);
pp.load(fis);
// 写文件:跟上面衔接
fos = new FileOutputStream(configpath);// 加载读取文件流
pp.setProperty("url1", "试试");// 修改值
pp.setProperty("url11", "111111");// 修改值
pp.store(fos, null);// 修改值
fos.close();
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
读取ini数据
String configpath = "D://QDPDFWriterDlg//target//classes//FilePath.ini";
FileInputStream fis = null; // 读
OutputStream fos;
Properties pp;
// 初始化并加载读取的文件
try {
pp = new Properties();
fis = new FileInputStream(configpath);
pp.load(fis);
pp.getProperty("ss");
System.out.println(pp.getProperty("ss"));
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}