• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem while adding record in the property file

 
ehsan ulhaq dar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code which add information in property file,

<%@ page contentType="text/html; charset=windows-1252" language="java" session="true" import="java.sql.*,java.util.*,com.towertech.util.*,java.io.*" errorPage="../error.jsp" %>
<%!
Properties prop = new Properties();
%>
<%
String ip = "1";
String ipAdres = "172.168.1.65";
String paa = "C:\IP.PROPERTIES";
FileOutputStream fos = new FileOutputStream(paa);
prop.setProperty(ip,ipAdres);
prop.store(fos,null);
fos.close();
%>
<jsp:forward page="WMPropertyFile.jsp"/>

this code work fine but when my server restart this code replace the existing values from the property file. I want to add the value in the existing values in property file.
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ehsan ulhaq dar wrote:Properties prop = new Properties();


This is the problem you're creating a new properties file each time.
Also you may end up with a concurrancy issue if more than one update to the property file is happening?
 
ehsan ulhaq dar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
then what its solution???
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ehsan ulhaq dar wrote:then what its solution???


You need to have a kind of check: "if file is there, use that, else create one".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!