[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1448
  • Last Modified:

writing : (colon) character problem

hi experts

i am writhng a property value to a properties file
using java propety object.
the value that i am trying to write is

jdbcurl=jdbc:mysql://192.168.0.60:3306/kessler

but the output in the file contains / befor every (:) colon like this

jdbcurl=jdbc/:mysql/://192.168.0.60/:3306/kessler

pls help to write waht i want to the file
0
Econify
Asked:
Econify
  • 4
2 Solutions
 
StillUnAwareCommented:
If it is there, then it should stay there. In other words if You used to write properties using Properties class, then it is assumed You are going to read the values back using the Properties file. This is the standard format for colon when writing special characters and if You will use Properties object to read the values back the string will stay unchanged.
0
 
EconifyAuthor Commented:

hi mr unaware
as ur name suggests
i didn't ask to explain me my problem.if possible please propose a solution. :(
0
 
fargoCommented:
you need to use Properties for reading and writing (both). The special characters will be taken care of automatically. Use the below link for more information
http://javaalmanac.com/egs/java.util/Props.html
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
StillUnAwareCommented:
import java.util.*;

public class Z2 {
  public static void main(String[] args) throws Exception {
    Properties p = new Properties();
    p.setProperty("jdbcurl", "jdbc:mysql://192.168.0.60:3306/kessler");
    p.store(new FileOutputStream("props.txt"), null);
    /*here You get the file output like this:
   
    #Thu Apr 27 12:08:27 EEST 2006
    jdbcurl=jdbc\:mysql\://192.168.0.60\:3306/kessler

    all special characters (including colon) are escaped using backslash (\).
    This is the default behaviour.*/
    p = new Properties();
    p.load(new FileInputStream("props.txt"));
    System.out.println(p.getProperty("jdbcurl"));
    //here You get the same string which was written to the file
  }
}
0
 
StillUnAwareCommented:
There is no other effective way to escape special characters, unless You do it manually.

P.S. the code is missing an import of java.io.* package.
0
 
StillUnAwareCommented:
Glad to help
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now