properties 文件操作
来源:互联网 发布:批量网页录入数据 编辑:程序博客网 时间:2024/05/29 18:51
public class readProperties {
private static Properties pro = new Properties();
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
public static void main(String[] args) throws IOException {
System.out.println(getPropertiesFile("src/count.properties", "num"));
}
public static String getPropertiesFile(String filepath, String key)
throws IOException {
InputStream input = new FileInputStream(new File(filepath));
pro.load(input);
String source = pro.getProperty(key);
if (source == null) {
source = "g" + sdf.format(new Date()) + "_00001";
pro.setProperty(key, source);
} else {
pro.setProperty(key, getNumber(source));
}
try {
OutputStream os = new FileOutputStream(new File(filepath));
pro.store(os, "pk identify");
pro.clear();
os.flush();
return getNumber(source);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private static String getNumber(String source) {
String str = source.substring(source.lastIndexOf("_") + 1);
int num = -1;
try {
num = Integer.parseInt(str) + 1;
} catch (NumberFormatException e) {
return null;
}
String r = "0000" + num;
r.substring(r.length() - 5);
return "g" + sdf.format(new Date()) + "_" + r;
}
}
private static Properties pro = new Properties();
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
public static void main(String[] args) throws IOException {
System.out.println(getPropertiesFile("src/count.properties", "num"));
}
public static String getPropertiesFile(String filepath, String key)
throws IOException {
InputStream input = new FileInputStream(new File(filepath));
pro.load(input);
String source = pro.getProperty(key);
if (source == null) {
source = "g" + sdf.format(new Date()) + "_00001";
pro.setProperty(key, source);
} else {
pro.setProperty(key, getNumber(source));
}
try {
OutputStream os = new FileOutputStream(new File(filepath));
pro.store(os, "pk identify");
pro.clear();
os.flush();
return getNumber(source);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private static String getNumber(String source) {
String str = source.substring(source.lastIndexOf("_") + 1);
int num = -1;
try {
num = Integer.parseInt(str) + 1;
} catch (NumberFormatException e) {
return null;
}
String r = "0000" + num;
r.substring(r.length() - 5);
return "g" + sdf.format(new Date()) + "_" + r;
}
}
- 操作properties文件
- java操作properties文件
- Java操作properties文件
- properties文件操作心得
- Java操作Properties文件
- properties文件操作类
- JAVA操作properties文件
- JAVA操作properties文件
- JAVA操作properties文件
- JAVA操作properties文件
- Properties文件操作
- JAVA操作properties文件
- JAVA操作properties文件
- JAVA操作properties文件
- Java操作properties文件
- java操作properties文件
- JAVA操作properties文件
- 操作properties属性文件
- 制作分享按钮
- php下载文件
- 从UIView的子类中推入视图控制器
- linux C经典面试题五
- PHP分页函数 自己收藏只用【上一页】123456【 下一页】
- properties 文件操作
- 什么是native compiler?什么是cross compiler?
- 中国最美的40个旅游景点
- string时间处理的很好
- VS2010 简单ATL COM开发(上)
- Java实现统计福彩双色球出现次数(毫无技术可言)
- hdu 1033 Edge
- fedora 安装xfce
- Delphi 图形设计(2)