Character '\' is lost when reading a String from a property file.

Hi all,
I have encrypted information inside a property file, but when loading properties in my program, the String object used to store the value is changed by the lost of all �\� characters
# EIS password saved in the property file
password=WPLqQE0DlVF8Sg\=\=
#Value loaded in my String object
WPLqQE0DlVF8Sg==
Why is this happening? I use java.util.Properties java class to store and load my properties, and it is supposed to do it with the same encoding (ISO 8859-1).
Please, can someone explain me why this happened and how to solve it?
Best regards.

      public static void main(String[] args) throws IOException {
           OutputStream props = new FileOutputStream("test.properties");
           Properties p = new Properties();
           p.put("password", "pass=word#is!dumb");
           p.put("user", "    I am a Dummy");
           p.store(props, "Java forum demo props file");
           props.close();
           /* Properties file after store
            * user=\    I am a Dummy
            * password=pass\=word\#is\!dumb
           Properties post = new Properties();
           post.load(new FileInputStream("test.properties"));
           for(Iterator it = post.entrySet().iterator(); it.hasNext();)
            System.out.println(it.next());
            * After load from test.properties
            * user=    I am a Dummy
            * password=pass=word#is!dumb
      }Notice that the special chars are only in the file, not actually in the props. If you think otherwise, I don't know what to say. The \ is a special character that is used to escape other special chars, including itself. You can't create a string in java containing only one backslash, as java assumes the next char is being escaped. when you create a string in Java with one backslash, you have to have 2 backslashes. If you are storing data in the property file using something other than store, than you need to ensure that you are escaping all special charachters that the store method does
~Tim

Similar Messages

  • Reading Each String From a text File

    Hello everyone...,
    I've a doubt in File...cos am not aware of File.....Could anyone
    plz tell me how do i read each String from a text file and store those Strings in each File...For example if a file contains "Java Tchnology forums, File handling in Java"...
    The output should be like this... Each file should contains each String....i.e..., Java-File1,Technology-File2...and so on....Plz anyone help me

    The Java� Tutorials > Essential Classes: Basic I/O

  • How to design and implement an application that reads a string from the ...

    How to design and implement an application that reads a string from the user and prints it one character per line???

    This is so trivial that it barely deserves the words "design" or "application".
    You can use java.util.Scanner to get user input from the command line.
    You can use String.getChars to convert a String into an array of characters.
    You can use a loop to get all the characters individually.
    You can use System.out.println to print data on its own line.
    Good luck on your homework.

  • How to read a string from file & assign the val to a variable in batch file

    Hi,
    How to read a string from a file and assign the value to a variable then return the value to the screen in windows batch file?
    Any suggestions?
    thanks.

    Unless this is a homework question then I don't see the purpose of doing this, but....
    You should be looking a the supplied package utl_file to get the string out of the file, dbms_output to display the string and then google windows batch/command files calling sqlplus to execute your program.
    Andre

  • Read 2 Strings from EXCEL with GOOP or ActiveX?

    Hello,
    i use Labview 5.1 with WIN NT4.0 SP6a and i programm a fuzzy Logic tool for a exam in Computer Science.
    Now i have a problem, and i read something about the GOOP and the EXCEL Toolkit. I download it and try more times to install but i can't link the *.llb in the Function Palette. Is this GOOP and Excel Toolkit only for Labview 6.x ?
    I solve it with ActiveX and Excel, but my very big Problem is, i need to read2 string from the Excel table from the same time, and with ActiveX i don't find any method how can i do that.
    I don't know how can i read 2 Strings from a Excel table, Can i do it with the Excel Toolkit,if yes how, maybe anyone make it or any helpfiles?
    Thanks for your answer in advance ,
    Ender
    Ekinci

    "fuzzylogic" wrote in message
    news:[email protected]..
    > Hello,
    > i use Labview 5.1 with WIN NT4.0 SP6a and i programm a fuzzy Logic
    > tool for a exam in Computer Science.
    > Now i have a problem, and i read something about the GOOP and the
    > EXCEL Toolkit. I download it and try more times to install but i can't
    > link the *.llb in the Function Palette. Is this GOOP and Excel Toolkit
    > only for Labview 6.x ?
    >
    > I solve it with ActiveX and Excel, but my very big Problem is, i need
    > to read2 string from the Excel table from the same time, and with
    > ActiveX i don't find any method how can i do that.
    >
    > I don't know how can i read 2 Strings from a Excel table, Can i do it
    > with the Excel Toolkit,if yes how, m
    aybe anyone make it or any
    > helpfiles?
    I'm pretty sure the excel toolkit is written for 5.1, and don't know why it
    would give you problems. Do you have excel installed? I'm not sure what
    you mean that you cant link the *.llb in function pallette. Have you tried
    opening the llb using '\functions\select a vi' ? As to how to read two
    cells at once, you could read a block of cells including both cells (ie:
    A5..D10) and then pull the data out of the array.

  • How to read some lines from a text file using java.

    hi,
    i m new to java and i want to read some lines from a text file based on some string occurrence in the file. This file to be read in steps.
    we only want to read the file upto the first Occurrence of "TEXT" string.
    How to do it ,,,
    Kinldy give the code
    Regards,
    Sagar
    this is the text file
    dfgjdjj
    sfjhjkd
    ghjkdg
    hjkdgh TEXT
    ikeyt
    ujt
    jk
    tyk TEXT
    rukl
    r

    Hendawy wrote:
    Since the word "TEXT" is formed of 4 letters, you would read the text file 4 bytes by four bytes. Wrong on two counts. First, the file may not be encoded 1 byte per character. It could be utf-16 in which case it would be two byte per character. Second, even if it were 1 byte per character, the string "Text" may not start on a 4 byte boundary.
    Consider a FileInputStream object "fis" that points to your text file. use fis.read(byte[] array, int offset, int len) to read every four bytes. Convert the "TEXT" String into a byte array "TEXT".getBytes(), and yous the Arrays class to compare the equality of the read bytes with your "TEXT".getBytes()Wrong since it relies on my second point and will fail when fis.read(byte[] array, int offset, int len) does not read 4 bytes (as is no guaranteed to). Check the Javadoc. Also, the file may not be encoded with the default character encoding.
    The problem is easily solved by reading a line at a time using a BufferedReader wrapping an InputStreamReader wrapping a FileInputStream and specifying the correct character encoding.
    Edited by: sabre150 on Apr 29, 2009 2:13 PM

  • I have a VI and an attched .txt data file. Now I want to read the data from the .txt file and display it as an array in the front panel. But the result is not right. Any help?

    I have a VI and an attched .txt data file. Now I want to read the data from the .txt file and display it as an array in the front panel. But the result is not right. Any help?
    Attachments:
    try2.txt ‏2 KB
    read_array.vi ‏21 KB

    The problem is in the delimiters in your text file. By default, Read From Spreadsheet File.vi expects a tab delimited file. You can specify a delimiter (like a space), but Read From Spreadsheet File.vi has a problem with repeated delimiters: if you specify a single space as a delimiter and Read From Spreadsheet File.vi finds two spaces back-to-back, it stops reading that line. Your file (as I got it from your earlier post) is delimited by 4 spaces.
    Here are some of your choices to fix your problem.
    1. Change the source file to a tab delimited file. Your VI will then run as is.
    2. Change the source file to be delimited by a single space (rather than 4), then wire a string constant containing one space to the delimiter input of Read From Spreadsheet File.vi.
    3. Wire a string constant containing 4 spaces to the delimiter input of Read From Spreadsheet File.vi. Then your text file will run as is.
    Depending on where your text file comes from (see more comments below), I'd vote for choice 1: a tab delimited text file. It's the most common text output of spreadsheet programs.
    Comments for choices 1 and 2: Where does the text file come from? Is it automatically generated or manually generated? Will it be generated multiple times or just once? If it's manually generated or generated just once, you can use any text editor to change 4 spaces to a tab or to a single space. Note: if you want to change it to a tab delimited file, you can't enter a tab directly into a box in the search & replace dialog of many programs like notepad, but you can do a cut and paste. Before you start your search and replace (just in the text window of the editor), press tab. A tab character will be entered. Press Shift-LeftArrow (not Backspace) to highlight the tab character. Press Ctrl-X to cut the tab character. Start your search and replace (Ctrl-H in notepad in Windows 2000). Click into the Find What box. Enter four spaces. Click into the Replace With box. Press Ctrl-V to paste the tab character. And another thing: older versions of notepad don't have search and replace. Use any editor or word processor that does.

  • Reading one line from a text file into an array

    i want to read one line from a text file into an array, and then the next line into a different array. both arays are type string...i have this:
    public static void readAndProcessData(FileInputStream stream){
         InputStreamReader iStrReader = new InputStreamReader (stream);
         BufferedReader reader = new BufferedReader (iStrReader);
         String line = "";          
         try{
         int i = 0;
              while (line != null){                 
                   names[i] = reader.readLine();
                   score[i] = reader.readLine();
                   line = reader.readLine();
                   i++;                
              }catch (IOException e){
              System.out.println("Error in file access");
    this section calls it:
    try{                         
         FileInputStream stream = new FileInputStream("ISU.txt");
              HighScore.readAndProcessData(stream);
              stream.close();
              names = HighScore.getNames();
              scores = HighScore.getScores();
         }catch(IOException e){
              System.out.println("Error in accessing file." + e.toString());
    it gives me an array index out of bounds error

    oh wait I see it when I looked at the original quote.
    They array you made called names or the other one is prob too small for the amount of names that you have in the file. Hence as I increases it eventually goes out of bounds of the array so you should probably resize the array if that happens.

  • How to read every line from a text file???

    How can i read every line from my text file ("eka.txt")
    now it only reads the first line and prints it out.
    What is wrong with this?
    import java.io.*;
    import java.util.*;
    class Testi{
         public static void main(String []args)throws IOException {
         BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
    File inputFile = new File ("eka.txt");
    FileReader fis =new FileReader(inputFile);
    BufferedReader bis = new BufferedReader(fis);
    String test=bis.readLine();
    String tmp= "";
    while((bis.readLine().trim() != null)) {
    int spacefound=0;
    int l=test.indexOf(" ");
         for(int i=0;i<test.length();i++){
         char c=test.charAt(i);
         if(c!=' ') tmp+=""+c;
         if(c==' ' && (spacefound<1) && !(tmp.equals(""))){
         tmp+=""+c;
         spacefound++;
         if(tmp.length()==l) {
         System.out.println(tmp);
         tmp="";
         spacefound=0;
         if(tmp.length()<l){
         for(int i=0;i<=(l-tmp.length());i++)
         tmp+=""+' ';
         System.out.println(tmp);

    Try this code, Hope it servers your purpose.
    import java.io.*;
    import java.util.*;
    class Testi {
         public static void main(String []args)throws IOException {
              BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
              File inputFile = new File ("Eka.txt");
              FileReader fis =new FileReader(inputFile);
              BufferedReader bis = new BufferedReader(fis);
              String test=bis.readLine();
              while(test != null) {
                   StringTokenizer st = new StringTokenizer(test," ");
                   while(st.hasMoreTokens())
                        System.out.println(st.nextToken());
                   test = bis.readLine();
    }Sudha

  • Reading rule sets from an XML file

    Hi all,
    How can I read rule sets from an XML file? I have been given some rules in XML
    format and using those I have to query some content. I am using WLP4.0
    Also how can I code rules in java?
    Thanks in advance.

    You can have the following classes:
    Players class deriving from Vector (or containing a vector), and then
    Player class with attribute 'name'.
    class Players
               Vector myVector = new Vector();
                void addPlayer(Player p)
                      myVector.add(p);
                Player getPlayer(int index)
                      myVector.get(index);
    class Player
             private String myName = null;
             Player(String name)
                    this.myName = name;
             String getName()
                    return myName;
    }Then while handling the SAX events you can do the following:
    class MySAXHandler implements ContentHandler (or whatever the itnerface is)
                 public void startElement(String name,....)
                          Players p = null;
                          if(name.equals("Players"))
                                 p = new Players();
                         else if (name.equals("Name"))
                                p.add(new Player(value));
    }HTH,
    Kalyan.

  • How to read configuration data from an xml file (not web.xml)?

    Hi,
    I want to separate the application specific configuration parameters in a separate xml file and read them as and when they are needed? I know that I can use the wb.xml but I want to separate them in a different xml file because I don't want the web.xml file to be played around later after deployment. If any change is needed then it should be done in the application-config.xml.
    How can I read the parameters from this xml file in my jsp code and also what should be the location of this file if I have
    ../webapps/Root/application
    directoty structure ?
    Any help is greatly appreciated.

    can you give an example of a property file and also
    it is loaded in the jsp ?Hmm... loading properties in a JSP is not a very good idea. You should do it in a separate class, rather than mixing the logic with the display logic.
    Properties properties = new Properties();
    properties.load(UtilClass.class.getResourceAsStream("config.properties"));
    // Add a try - catch block around the load
    // for IOException...

  • Populate a table reading the data from a TXT file

    how can I populate a table reading the data from a TXT file?
    thanks

    Hey Kevin!
    Using FORMS.TEXT_IO to bulk load data from a file strikes me as re-inventing the wheel. It is just about justifiable in a self-service environment, but I regard the EXTERNAL TABLE is a better solution for that situation as well.
    The same applies to UTL_FILE. I think the ability to read text with UTL_FILE is primarily intended for read file-based configuration or file manipulation/processing rather than data loading.
    Re-writing a text file into SQL statements is too much like hard work (even with an editor that supports macro definition and regular expressions) for no real benefit. You lose all the bulk load peformance you would get from SQL*Loader. But for QAD I'd probably let you off with it.
    You missed out one obvious alternative: using Java to turn the contents of an XML file into a CLOB and inserting it into a table which is read by a PL/SQL procedure that parses the XML records and insert the retrieved data into a table.
    Stay lucky, APC

  • How do i read complete line from a text file in j2me?????

    how do i read complete line from a text file in j2me????? I wanna read file line by line not char by char..Even i tried with readUTF of datainputstream to read word by word but i got UTFDataFormatException.. Please solve my problem.. Thanks in advance..

    That is not my problem . i already read it char by char.. i am getting complete line..But this process is taking to much time..So thats why i directly wanna read complete line or word to save time..

  • How to read a table from a word file, using HWPF

    How can I read a table from a Word file using HWPF?
    I looked in API and Table class doesn't seem to have a constructor... very very strange for me. pls help

    the constructor is HWPFDocument = new HWPFDocument(/*file*/)
    Here is the API for that
    http://poi.apache.org/apidocs/org/apache/poi/hwpf/HWPFDocument.html
    Also here is another link to something that might help you more with tables
    http://www.aspose.com/Community/forums/thread/79182.aspx

  • Reading each value from spreadshee​t file with delay (multiple rows and columns)

    Hi,
    a) I want to read EACH VALUE from a spreadsheet file having multiple rows and columns WITH DELAY. I am attaching my VI and sample datalog file for reference (tempsensor.txt).I need to do so because as soon as I read put ON the Sensor button on front panel, LV reads all the values at one go. I need the values for each temperature to be displayed after a delay.
    b) Secondly, I would like to read another file containing the state of four antennas (deployed:1; undeployed:0). I am logging state of each antenna in each column of the file(magnet.txt) I need to have four LEDS on front panel to display state of the antennas. I dont know what I have done for antennas in my VI is right or wrong. I guess thats rhe wrong way to approach the problem. Please help!!!(column1: Antenna1 state ; Column2:Antenna2 state.. and so..on..)
    Any help would be greatly appreciated!!
    Thanks in advance,
    Ratnesh
    FYI: The first column in my datalog file represents timestamp(number of seconds elapsed), second column: reading for temperature sensor 1, third column: reading for temperature senosr 2, and so on. I am using approx. 11 temperature sensors.
    Also, I have generated the log files for the reference purpose only. They do not represent the actual values. They are far away from actual values.
    Attachments:
    01032005.zip ‏30 KB

    Look at this modified version of your VI. After looking at it, I determined that a shift reggister was not required in this case.
    Lynn
    Attachments:
    MultiSensors.2.vi ‏85 KB

Maybe you are looking for