先贴代码File file = new File("database.properties"); if(!file.exists()) { file.createNewFile(); } InputStream fis = new FileInputStream(file); Properties prop = new Properties(); prop.load(fis); prop.setProperty("url", url); prop.setProperty("driver", driver); prop.setProperty("user", user); prop.setProperty("password", password); OutputStream fos = new FileOutputStream(file); prop.store(fos, url); prop.store(fos, driver); prop.store(fos, user); prop.store(fos, password); }执行结果,properties文件内容#jdbc:mysql://127.0.0.1:3306/test?autoReconnect=true&useSSL=false#Wed Aug 03 11:41:07 CST 2016user=rootpassword=123456url=jdbc\:mysql\://127.0.0.1\:3306/test?autoReconnect\=true&useSSL\=falsedriver=com.mysql.jdbc.Driver#com.mysql.jdbc.Driver#Wed Aug 03 11:41:07 CST 2016user=rootpassword=123456url=jdbc\:mysql\://127.0.0.1\:3306/test?autoReconnect\=true&useSSL\=falsedriver=com.mysql.jdbc.Driver#root#Wed Aug 03 11:41:07 CST 2016user=rootpassword=123456url=jdbc\:mysql\://127.0.0.1\:3306/test?autoReconnect\=true&useSSL\=falsedriver=com.mysql.jdbc.Driver#123456#Wed Aug 03 11:41:07 CST 2016user=rootpassword=123456url=jdbc\:mysql\://127.0.0.1\:3306/test?autoReconnect\=true&useSSL\=falsedriver=com.mysql.jdbc.Driver为什么每一个prop.store(),会把所有的prop.setProperty()都写入到输出流?
添加回答
举报
0/150
提交
取消