有一个配置文件 core.properties里面有整个工程需要用到的配置参数 如数据库的配置,外联系统的参数,还有其他。还有两个参数 我需要把它那出来经过处理后再放回去。 不知为何修改不成功。。麻烦各位指教。。
public class AESkeyprocess {
public static String Encrypt(String sSrc) throws Exception {
AESkeyprocess loadProp = new AESkeyprocess();
InputStream in = loadProp.getClass().getResourceAsStream(
"/com/bca/config/core.properties"); Properties prop = new Properties(); try {
prop.load(in);
} catch (IOException e) {
e.printStackTrace();
} String skey = prop.getProperty("key1", "none");
byte[] clear = skey.getBytes();
byte[] key = "qwerfdes32456yht";
//PKCS5Padding or NoPadding
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(clear);
String encrypkey = new String(encrypted.toString());
prop.setProperty("key1", "");
prop.setProperty("key2", encrypkey);
in.close()
return AESkey1;
}
}执行结果是没有修改 为什么??
public class AESkeyprocess {
public static String Encrypt(String sSrc) throws Exception {
AESkeyprocess loadProp = new AESkeyprocess();
InputStream in = loadProp.getClass().getResourceAsStream(
"/com/bca/config/core.properties"); Properties prop = new Properties(); try {
prop.load(in);
} catch (IOException e) {
e.printStackTrace();
} String skey = prop.getProperty("key1", "none");
byte[] clear = skey.getBytes();
byte[] key = "qwerfdes32456yht";
//PKCS5Padding or NoPadding
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(clear);
String encrypkey = new String(encrypted.toString());
prop.setProperty("key1", "");
prop.setProperty("key2", encrypkey);
in.close()
return AESkey1;
}
}执行结果是没有修改 为什么??
FileOutputStream stream = new FileOutputStream(new File(filePath));
properties.store(stream, "DataBase Conf File Info");
stream.close();
请问一下,如果加上述语句的话,’filePath‘应该怎么写呢? 怎么指定路径呢 ?如读取的时候的路径’/com/bca/config/core.properties ‘
Properties config=new Properties();//记录配置项
try {
config.load(new FileInputStream("integrate.properties"));
config.setProperty("password",text_5.getText());
FileOutputStream outputFile = new FileOutputStream("integrate.properties");
config.store(outputFile, "test");
outputFile.close();
} catch (Exception e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
请问一下 。 “FileOutputStream outputFile = new FileOutputStream("integrate.properties");” 能自己指定路径吗? 比如integrate.properties在一个JAVA工程的某个包里,比如在 src/config/里,该怎样指定路径呢? 谢谢
相对路径
config/integrate.properties
"/com/bca/config/core.properties").getFile();
byte[] key="dadfafdsa"; //有这样的用法?
还有InputStream是输入流,不能写出到文件中的?
LZ的这代码是不是在IDE上编辑的?不报错吗
运行期间不能修改这个jar包的。
是不是不能用相对路径的??????????
output 的 路径 和input 的路径是一样的。
你怎么造出input的,就怎么造出output呀