创建properties文件保存在WEB项目的classes文件下
2013-10-24 15:08
197 查看
1、保存数据
2、读取数据
private synchronized boolean saveFile(String url,String filename){ try { String path = servletRequest.getSession().getServletContext().getRealPath("/"); System.out.println(path); path+="WEB-INF\\classes\\"; File file = new File(path+filename); if(file.exists()){ file.delete(); } Properties prop = new Properties(); prop.setProperty("username",dbusername); prop.setProperty("password",dbpassword); prop.setProperty("url",url); FileOutputStream fos = new FileOutputStream(file); prop.store(fos, null); fos.close(); return true; } catch (Exception e) { e.printStackTrace(); } return false; }
2、读取数据
private synchronized String readFile(){ String jsonString="{}"; try { InputStream in = TestDbConnection.class.getClassLoader().getResourceAsStream(filenames[projectType]); if(in!=null){ Properties properties = new Properties(); properties.load(in); String nameString = properties.getProperty("username"); String password = properties.getProperty("password"); String vip = properties.getProperty("ip"); String vdbname = properties.getProperty("dbname"); String vtype = properties.getProperty("dbtype"); jsonString="{username:\""+nameString+"\",password:\""+password+"\",ip:\""+vip+"\",dbname:\""+vdbname+"\",dbtype:\""+vtype+"\"}"; System.out.println(" jsonString: "+jsonString); } } catch (Exception e) { e.printStackTrace(); } return jsonString; }
相关文章推荐
- java web项目中classes文件夹下的class和WEB-INF/lib中jar里的class文件加载顺序
- java web项目中classes文件夹下的class和WEB-INF/lib中jar里的class文件加载顺序
- Eclipse中maven项目没法自动编译、编译失败、WEB-INF/classes目录中没有Class文件
- Eclipse WEB项目部署缺少classes文件
- MyEclipse编译后,classes文件夹下为空2. 3.删除现在的项目,提前设置好编译文件输出路径,重新导入源文件,设置eclipse为保存时编译,然后在保存的时候就可以自动编译了
- java web项目中classes文件夹下的class和WEB-INF/lib中jar里的class文件加载顺序
- Eclipse中maven项目没法自动编译、编译失败、WEB-INF/classes目录中没有Class文件
- Eclipse项目不编译,WEB-INF/classes文件夹中没有文件
- Eclipse中maven项目没法自动编译、编译失败、WEB-INF/classes目录中没有Class文件
- web 工程下 java操作属性文件保存在classes下的读写操作
- Eclipse 项目无法自动编译,WEB-INF/classes目录下没有class文件的解决过程
- Javaweb项目中,jsp页面读取 WEB-INF/classes 下的 properties文件
- java web项目中classes文件夹下的class和WEB-INF/lib中jar里的class文件加载顺序
- Tomcat报错: /项目名/WEB-INF/classes文件为空
- web项目获取运行时...\WEB-INF\classes目录下文件
- eclipse中maven web项目部署时缺少classes文件或者resources文件
- 在tomcat运行找不到xml,class ,项目中的java文件没有在WEB-INF\classes中生成class文件
- eclipse 项目中的java文件没有在WEB-INF目录下的classes中 生成相对应的编译后的类
- Java输出文件到web项目的classes下
- java web项目中的java读取WEB-INF和classes下的文件