有一个配置文件 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;
}
}执行结果是没有修改  为什么??

解决方案 »

  1.   

    修改properties文件还需要以下语句
    FileOutputStream stream = new FileOutputStream(new File(filePath));
    properties.store(stream, "DataBase Conf File Info");
    stream.close();
      

  2.   


    请问一下,如果加上述语句的话,’filePath‘应该怎么写呢? 怎么指定路径呢 ?如读取的时候的路径’/com/bca/config/core.properties ‘ 
      

  3.   

    给你一个小例子
    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();
      

  4.   


     请问一下 。 “FileOutputStream  outputFile = new FileOutputStream("integrate.properties");” 能自己指定路径吗? 比如integrate.properties在一个JAVA工程的某个包里,比如在 src/config/里,该怎样指定路径呢?  谢谢
      

  5.   


    相对路径
    config/integrate.properties
      

  6.   

    filePath = loadProp.getClass().getResourceAsStream( 
    "/com/bca/config/core.properties").getFile(); 
      

  7.   

    这代码怎么这么乱乱的呢?
    byte[] key="dadfafdsa"; //有这样的用法?
    还有InputStream是输入流,不能写出到文件中的?
    LZ的这代码是不是在IDE上编辑的?不报错吗
      

  8.   

    从楼主的代码看是jar包运行吗?
    运行期间不能修改这个jar包的。
      

  9.   

    FileOutputStream  outputFile=new FileOutputStream(); 
     是不是不能用相对路径的??????????
      

  10.   

    lz,
    output 的 路径 和input 的路径是一样的。
    你怎么造出input的,就怎么造出output呀