标签:imp tool stat catch todo close throw exception not
package com.jm.label.tools;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* 修改Properties
* @author win 10
*
*/
public class PropertiesUtils {
/**
* 修改文件内容
* @param store_name
* @param mend_text
* @param importprf
* @throws IOException
*/
public static void modification(String store_name,String mend_text,String importprf) {
try {
Properties prop = new Properties();
FileInputStream fis = new FileInputStream(importprf);
//将流中的数据加载进集合
prop.load(fis);
prop.setProperty(store_name , mend_text);
FileOutputStream fos = new FileOutputStream(importprf);
prop.store(fos,"modification");
fos.close();
fis.close();
} catch (IOException e) {
System.err.println("PropertiesUtils错误");
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
}
//prop.list(System.out);
}
/**
* 添加文件内容
* @param store_name
* @param mend_textadd
* @param importprf
* @throws IOException
*/
public static void add(String store_name,String mend_text,String importprf) {
Properties prop = new Properties();
FileInputStream fis;
FileOutputStream fos;
try {
fis = new FileInputStream(importprf);
//将流中的数据加载进集合
prop.load(fis);
prop.setProperty(store_name , mend_text);
fos = new FileOutputStream(importprf);
prop.store(fos,"add");
//prop.list(System.out);
fos.close();
fis.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 读取文件内容
* @param store_name
* @param importprf
* @return
*/
public static String show(String store_name,String importprf) {
Properties prop = new Properties();
try {
InputStream in = new FileInputStream(new File(importprf));
prop.load(in);
} catch (IOException e) {
System.err.println("PropertiesUtils错误");
// TODO Auto-generated catch block
e.printStackTrace();
}
return prop.getProperty(store_name);
}
public static void main(String[] args) throws IOException {
modification("FileName", "tes123t456", "time.properties");
add("Sql", "jm123456", "time.properties");
show("FileName", "time.properties");
show("Sql", "time.properties");
}
}
标签:imp tool stat catch todo close throw exception not
原文地址:https://www.cnblogs.com/java-h/p/10584012.html