Commit 8cfa25ef authored by 李德才's avatar 李德才

支持中文

parent 60798c9e
......@@ -5,7 +5,6 @@ import com.jfinal.aop.Clear;
import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.jfinal.kit.StrKit;
public class SnController extends Controller {
......
......@@ -4,7 +4,6 @@ package com.archser.aserver.service;
import com.archser.aserver.util.PropertyUtil;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.redis.Redis;
import java.io.File;
......@@ -37,26 +36,4 @@ public class SnService {
}
/**
* 向 Properties 写入
*
* @param cupCode
* @param snCode
*/
public void setProperty(String cupCode, String snCode) {
PropertyUtil.setProperty(cupCode, snCode, FILE_PATH);
}
/**
* 将序列号信息写入Redis
*
* @param cpuCode
* @param snCode
* @return
*/
public String saveSnToRedis(String cpuCode, String snCode) {
return Redis.use().set(cpuCode, snCode);
}
}
package com.archser.aserver.util;
import com.jfinal.kit.PropKit;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Properties;
......@@ -20,31 +21,16 @@ import java.util.Properties;
*/
public class PropertyUtil {
static final String filePath = "D:\\workspace\\PublicSource\\aserver\\src\\main\\webapp\\SN.properties";
static final String copyFilePath = "D:\\workspace\\PublicSource\\aserver\\src\\main\\webapp\\SN2.properties";
public static Properties loadResource(String propFile) throws IOException {
Properties properties = new Properties();
InputStreamReader reader = new InputStreamReader(
PropertyUtil.class.getResourceAsStream(propFile));
InputStreamReader reader = new InputStreamReader(PropertyUtil.class.getResourceAsStream(propFile));
properties.load(reader);
return properties;
}
public static String get(String filePath, String key) {
Properties prop = null;
try {
prop = loadResource(filePath);
} catch (IOException e) {
e.printStackTrace();
}
String title = null;
try {
assert prop != null;
title = new String(prop.getOrDefault(key, null).toString().getBytes(), "UTF-8");
} catch (UnsupportedEncodingException ignored) {
}
return title;
}
/**
* 读取配置文件中的值
*
......@@ -59,7 +45,7 @@ public class PropertyUtil {
input = new FileInputStream(filePath);
BufferedReader bf = new BufferedReader(new InputStreamReader(input));
props.load(bf);
value = new String(props.getProperty(key).getBytes(StandardCharsets.ISO_8859_1),StandardCharsets.UTF_8);
value = props.getProperty(key);
} catch (IOException e) {
e.printStackTrace();
} finally {
......@@ -84,12 +70,14 @@ public class PropertyUtil {
Properties props = new Properties();
OutputStream out = null;
InputStream input = null;
FileOutputStream oFile = null;
try {
input = new FileInputStream(filePath);
oFile = new FileOutputStream(new File(filePath), true);//true表示追加打开,false每次都是清空再重写
props.load(input);
props.setProperty(key, value);
out = new FileOutputStream(filePath);
props.store(out, null);
props.store(new OutputStreamWriter(oFile, StandardCharsets.UTF_8), "III");
} catch (IOException e) {
e.printStackTrace();
} finally {
......@@ -106,4 +94,11 @@ public class PropertyUtil {
}
}
public static void main(String[] args) {
String key = "AAA";
String value = "数字档案室3,cdcsdcdscd";
setProperty(key, value, filePath);
// System.err.println(PropKit.use(new File(filePath)).get(key));
}
}
cfc84f0ff5395302517acc5ded7e7101f415cb953d535833296b292fa0f9c5ae=huayiwendang,04c5c8a0db17ff09e046e64099dbe532fc2c79e0f8898a4351234d96049055964448a10b4d1459e598532c33069a1b1293d2d6aeb66ca28448a622a364fdeec28e781180b7cbf8738b654860ac18dd2592d055ee3d1a1104b747c7f43070ae0e1102287bd0a6f84113a629e4eb9a4f5f7c4628c691416ab536201bccfd8f5d3fe44e7bb737760dd21edff98347200a0d258b5097fc252b3c41401f2bb26683f2aa56e220c85fb83ae653e1a26a11adf14564383578e7d202d9c83f7130b4c912e8295f8c9fa93deb20dbbe18e1fcc2cbd7e281d5acfe5b01ad61477542c335012b8753a27a52f164990743194b1314885a
\ No newline at end of file
#III
#Wed Dec 02 15:35:36 CST 2020
AAA=数字档案室3,cdcsdcdscd
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment