Properties 使用,注意编码
Posted donaldlee
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Properties 使用,注意编码相关的知识,希望对你有一定的参考价值。
private static void setConfig(){ try { // String path = System.getProperty("user.dir") + "\\dbpool.properties"; String path = "./lib/setting.txt"; // FileInputStream is = new FileInputStream(path); Properties props = new Properties(); // props.load(is); props.setProperty("dslname",textField.getText().trim()); props.setProperty("dslacc",textField_1.getText().trim()); props.setProperty("dslpsw",textField_2.getText().trim()); //props.store (is); PrintStream fW = new PrintStream(new File(path)); props.list(fW ); // timeout = Integer.parseInt(props.getProperty("timeout")); // waitforresult=Integer.parseInt(props.getProperty("waitforresult")); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); System.err.println("????????????"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); System.err.println("??????????????"); } } private static void readConfig(){ try { // String path = System.getProperty("user.dir") + "\\dbpool.properties"; String path = "./lib/setting.txt"; FileInputStream is = new FileInputStream(new File(path)); // FileInputStream. Properties props = new Properties(); InputStreamReader reader = new InputStreamReader(is,"UTF-8"); props.load(reader); //props.load(is); dslname=props.getProperty("dslname"); dslacc=props.getProperty("dslacc"); dslpsw=props.getProperty("dslpsw"); textField.setText(new String(dslname.getBytes("utf-8"),"utf-8")); textField_1.setText(dslacc); textField_2.setText(dslpsw); // timeout = Integer.parseInt(props.getProperty("timeout")); // waitforresult=Integer.parseInt(props.getProperty("waitforresult")); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); System.err.println("????????????"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); System.err.println("??????????????"); } }
以上是关于Properties 使用,注意编码的主要内容,如果未能解决你的问题,请参考以下文章
SpringBootMybatis 关于Mybatis-generator-gui的使用|数据库的编码注意点|各项复制模板
solr分布式索引实战分片配置读取:工具类configUtil.java,读取配置代码片段,配置实例