Writing to properties files

I read the earlier posts about this, but still have questions.
We need to write to a properties file to store user settings. We want to create two properties files. The first will not be edited by users and will be included in the jar file. This file will reference a second file that will be changed by users and will be stored on their machines.
Will this work? Where on the user's machine should we put the second file? Does it matter?

this will work fine.
user.home is a good place to put the file.

Similar Messages

  • Doubt on writing a properties file in to jar file

    hi,
    I have a jar file. In that jar file, I have a folder, named '/data/'. In this data folder i want to write a properties file. how to write?
    i was tried using the store method but i did not get it
    can any one help me out.
    thank you.

    You want to place the log4j.properties inside the .jar? You can read the log4j.properties inside the jar and give the Properties to log4j like this:
    String propertiesFile= "pathInJar/log4j.properties";
    InputStream in = getClassLoader().getResourceAsStream(propertiesFile);
    if (in != null)
        Properties props = new java.util.Properties();
        props.load(in);
        PropertyConfigurator.configure(props);
    else
       //PropertiesFile not found! (Handle the problem)
    }

  • Writing to properties file

    Hi,
    Is there any way by which we can write to the appearance.properties file in OPA through some VM file using VTL?
    Any other way to read and write to any file from OPA vm files will also do.
    Thanks.

    There might be, but I wouldn't recommend it!

  • Problem in writing Hindi Font in properties file at run time.!

    hi,
    We are using Language translator for our project.
    We are able to convert the language in hindi and chinese language.
    Im also creating properties file respective to each page in hindi,english and chinese language.
    At run time while CREATING properties file shows the english font appropriate but while
    in hindi it shows problem at run time .
    after WRITING at run time the hindi properties file contains lots on question mark(????????????) intead of hindi font words.
    does any advise me the solution to this problem.?
    Thankx in advance.!
    Johnita

    Hi suraya,
    Since the issue regards MVC and website deployment. I suggestion you post the question in the ASP.NET forums at
    http://forums.asp.net/. It is appropriate and more experts will assist you.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Problem in writing to the file

    I use this labview code to read and save some electrical measurement data from a set of instruments. I am having a problem that the code stops writing to the file after a while. It stops responding too. The only way to stop it then is to use the task manager and kill it. The code was written for an older version of labview but now I am using labview 9. Everything else seems updated but there's a section that uses Write characters to file vi and that may be causing the problem. I made a few futile attempts to change it. I would highly appreciate if someone takes a look at it and could tell me what's going wrong.
    Attachments:
    JANUS 2.2_4K Probe edit (2).vi ‏60 KB

    I will second aeastet's advice - please look into how state machines and producer/consumer loops work and use them.  Your program is very inefficient, but is very similar to what I would have written before I learned about state machines and producer/consumer loops.  Start with the LabVIEW help and go from there.  These forums and the National Instruments website can give you lots of help.
    Two things that will help you for this particular problem:
    At every loop iteration, you are opening the file, seeking to the end of it, appending data, then closing the file.  This is very slow and the code you use, as mentioned above, will not work if the file size exceeds 2GBytes.  I would recommend you open the file once, then use the write primitive to write to it until you finish, then close it.  You do not need the write character to file VI.  No seeking.  No repetitive opening and closing.  You can either open and close outside the loop, or use case structures and boolean flags (as you have done for other things) to open and close inside the loop.
    After you write to the file, if you choose to graph, you are reopening the file, reading the entire thing, and plotting this data.  This is another major slowdown that will only get worse as your file gets bigger.  You would be far better off caching the data in a shift register and plotting it on demand.  It would probably take less memory, as well.  You may want to read the tutorial Managing Large Data Sets in LabVIEW.
    One last tip.  You use Value properties to read and set the values of front panel controls.  Local variables are far faster (about three orders of magnitude).  However, do not make the mistake of using local variables for data storage.  Data is wires.  Local variables are a way to communicate to the front panel.  You seem to have this down, but a reminder to others reading this thread is in order.
    Let us know if you need more explanation or help.  Good luck!
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • Need example of properties file use

    I'm writing a text based adventure game to get some practice with the Java language. The only thing that's proving to be difficult is saving the game. I need an example of a class for basic properties operations. I've found various tutorials that all have some helpful information, but putting it all together isn't working for me. Here is what I have.
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    public class SaveGame{
    public static void CreateSave(String name){//create the save file
        try{
            FileWriter fstream = new FileWriter(name+".properties");
            BufferedWriter out = new BufferedWriter(fstream);
            out.write("*-=Character Information=-*");
            out.write("name= \ngender= \n");
            out.write("*-=Basic Stats=-*");
            out.write("str= \nagl= \nend= \nchr= \nitl= \nlck= \n");
            out.close();
            }catch(Exception e){System.err.println("Error: " + e.getMessage());}
    }//CreateSave
    public static void SaveStatus/*save all variables to the file*/
    (double str, double agl, double end, double chr, double itl,
      double lck, String name, char gender){
    // I don't know how to edit values
    }//SaveStatus
    public static void ReadSave(){//reads the file and sends the variable back to main class
    }//ReadSave
    }//class The big thing is, I don't know how to edit the values in the properties file. I can handle reading them but i don't know how to convert the string values to int, double, etc. Thanks in advance.

    Dillon_91 wrote:
    Thanks for those.
    Can you link to a decent tutorial on the properties class? Most of what I've found is a little more technical than I'm ready for, and they don't have examples.Suns own Java tutorial has some code snippets, that should get you going - [Properties tutorial|http://java.sun.com/docs/books/tutorial/essential/environment/properties.html]

  • Best way to load messages - properties file or database?

    Hi Guys,
    I have a debate with my colleague about best way to load/keep GUI messages.
    As we known, all those messages are in properties file, web tier will handle the messages loading to GUI.
    However, my colleague suggested, we could save all the messages in a database table, when application starts up, it will load all the messages from database.
    Please help me figure out pros/cons for both ways? What's the best to deal with message loading?
    Thanks

    allemande wrote:
    Please help me figure out pros/cons for both ways?There is no big difference with regard to performance and memory use. Both are after all cached in memory at any way. I wouldn't worry about it.
    The biggest difference is in the maintainability and reusability. Propertiesfiles are just textbased files. You can just edit the messages using any text editor. It is only a bit harder to wrap it in a UI like thing, but you can achieve a lot using java.util.Properties API with its load() and store() methods. Another concern is that it cannot be used anymore if you switch from platform language (e.g. Java --> C# or so) without writing some custom tool to read Java style properties files at any way. Databases, on the other hand, require SQL knowledge or some UI tool to edit the contents. So you have to create a UI like thing at any way if you want to let someone with less knowledge edit the messages. This is more time consuming. But it can universally be used by any application/platform by just using SQL standard.

  • Read a properties file

    hi all,
    i do have a java class, it's a WebService in fact, coded in java. I must add something, and as i learned by myself java there some things i don't know.
    my class must access to a properties file to store data like server, dbs path etc... this file will also be changeable by an administrator on the machine
    i'have seen that with java.util.Properties there is a method to save the properties into an outputstream (consequently into a file i guess), but i have never dealed with output and files, so i'm a bit lost, could someone give me some clues, or a link to some code ?
    regards

    Here is some code. These methods just override methods in java.util.Properties with a new instance of a Properties-like class called MyProperties. To make an instance of this class, just pass in the file name into the constructor. THIS CODE WON'T WORK BY ITSELF AND YOU WILL NEED TO MAKE MODIFICATIONS! It's just some old code i pulled down from an old app i wrote. A better way to do this would be just extending from java.util.Properties, but i don't have time to fix it.
    public MyProperties (String name) throws FileNotFoundException,IOException {
              this.name = name;
    //creates input stream of the file you passed in
              inFile = new BufferedInputStream(new FileInputStream(name));
    //instance of java.util.properties
              prop = new Properties();
              prop.load(inFile);
         //containsKey wrapper
         public boolean containsKey(String key) {                                   //'key' is the key you search for in the 'name' file
              return prop.containsKey(key);
         //saves the passed value to the specified key (writes to the file). Define 'header' to add a header message at the beginning of the file.
         public void store(String header) throws IOException {
    //your output file...in this case, it's also the input file     
    BufferedOutputStream outFile = new BufferedOutputStream(new FileOutputStream(name));
              prop.store(outFile,header);
              return;
         // setProperty
         public void setProperty(String key, String attribute) {                    //sets the key 'key' to the value 'attribute'
    //before writing to the file, YOU should check whether the user has admin privileges!     
    prop.setProperty(key, attribute);
         // getProperty
         public String getProperty(String key) {                                        //gets the value of the key 'key'
         String theAttribute = prop.getProperty(key);
         return theAttribute;

  • Updating properties file with values containing characters like slash (/)

    Hi,
    I am writing a java class that would create/update properties file. I am passing a string that contains colons. e.g. a path like
    http://xyz.com
    I am using the java.util.Properties.setProperty(String arg0, String arg1) method to set the key value and the java.util.Properties.store(OutputStream arg0, String arg1) to create/update the properties file.
    The resulting property file contains the value as http\://xyz.com
    A slash preappended to the colon.
    I do not want this slash to be preappended.
    How can I achieve that?

    If you don't want this escaping to happend, then you don't want to be using java.util.Properties. Those define the file format in a certain way that includes escaping those characters.
    If you don't want this, you'll have to write them using normal Writers (and read them using Readers) with your own parsing/storing logic added.

  • About properties file values in descendind order

    hi,
    I have one query . I have one properties file ab.txt in that
    user       marks
    a    =           1
    b     =           5
    c      =           8
    here my query is  now i want to display marks in descendindgorder
    can any one give idea about this one

    Fine that it works for you, but please keep in mind: writing raw java code in a JSP file is a bad practice. Whenever you need to do so, your design is flawed. You should be using tablibs (JSTL, JSF, etc), EL and/or Java classes (servlets, beans, etc).
    You´ve been warned.

  • How to save a properties object to a file / how to create a properties file

    hi,
    i am writing an application in which all the database and user information is stored in a properties object and is later retreived from it when a database connection or login etc is required.
    i wanna know how can i save this object / write it to a file i.e. how do i create a properties file.
    so that every time the application is run to create a new dbase etc the entire info regarding that will be stored in a new property file.

    Load:
    Properties p = new Properties();
    FileInputStream in = new FileInputStream("db.properties");
    p.load(p);
    String username = p.getProperty("username");
    String password = p.getProperty("password");
    // ...Save:
    String username = "user";
    String password = "pw";
    Properties p = new Properties();
    p.setProperty("username", username);
    p.setProperty("password", password);
    FileOutputStream out = new FileOutputStream("db.properties");
    p.store(out, null); // null or a String header as second argumentThe file will look something like
    username=user
    password=pw

  • Writing in INF file  Problem!

    Hi
    I've successfully read from INF file by the following code :
        public String Read_INI(String Path , String Attribute)
            Properties p = new Properties();
            try
                p.load(new FileInputStream(Path));
            catch (Exception e)
                    System.out.println(e);
            return p.getProperty(Attribute);
        }Now I'm facing a problem in writing in INF file
    i used this code but it doesn't work!
        public void Write_INI(String Value, String Attribute, String Path)
            Properties p = new Properties();
            try
                   p.load(new FileInputStream(Path));
                   p.setProperty(Attribute, Value);
            catch (Exception e)
                    System.out.println(e);
        }any ideas ?

    thnx very much :)
    just i added :
                   p.store(new FileOutputStream(Path), Value);after :
         p.setProperty(Attribute, Value);

  • Properties file in jar

    When I build my application, I put the properties file in the jar file. I can easily read the properties file from there using
    ClassLoader.getSystemResourceAsStream
    but is there a way to actually UPDATE the properties in the properties file if it's included in the jar file I'm executing? Or, would I have to put the properties file outside of the jar to be able to update individual properties from within the code?

    I would use the one inside the jar only if one externally does not work. If your jar is used by multiple users, you might want to store this in a place like $USER_HOME/.project_name/property_file so individual users can have their own properties. If the user has no properties, then load it from the jar.
    If multiple users is not an issue, you could store it externally. I see no reason not to. You can store it internally, but you risk corrupting the original jar (say the power goes out while writing a new jar or updating it) You could do it with java.util.jar, or if the jar executable is available (or even a zip for that matter) you could call that to update the jar with the new properties file using Runtime and exec.

  • Help on properties file

    I am writing following code to read parameters from properties file (using java.util.properties) but it does not give any output. Please help ASAP.
    CODE::
    FileInputStream propFile = new FileInputStream("cont.properties");
              String dbUrl = "";
    Properties props = new Properties();
    props.load(propFile);
         props.getProperty("DatabaseUrl",dbUrl);
         System.out.println("DatabaseUrl = " + dbUrl);

    I am finding one probelm.
    it seems your property file contents is
    dbUrl="1.2.3.4"; but it should be
    DatabaseUrl="1.2.3.4";
    Try this out.
    Code is :
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.util.Properties;
    public class Test {
         public Test() {
         public static void main(String args[])
              try {
                   FileInputStream fis = new FileInputStream("temp.prop");
                   String dbUrl = "";
                   Properties prop = new Properties();
                   prop.load(fis);
                   dbUrl = prop.getProperty("DatabaseUrl",dbUrl);
                   System.out.println("DatabaseUrl="+dbUrl);
              } catch (FileNotFoundException e) {
                   System.out.println("file not found");
              } catch (IOException e) {
                   System.out.println("ioexception");

  • Error reading properties file upon deployment

    hi. i'm still relatively new with regards to the Java programming language. in any case... i am developing a simple project wherein the application has to make a database connection to a server. the application is finished already however.. i am having problems deploying it.
    my project has a "resources" package containing the file "config.properties" which contains various information (connection details among others). correct me if im doing something wrong, but in deploying in, i copied the "dist" folder of my compiled code and then tried to run the java exe independently which resulted in an error. i already tried copying the "config.properties" file to the dist folder and even creating a "resources\config.properties" file but it still results in an error. could you please help me figure out how to deploy the application with the properties file. the code i used in referencing my .properties file is as follows:
    Properties configFile = new Properties();
                configFile.load(this.getClass().getClassLoader().getResourceAsStream("Resources\\config.properties"));
                String username = configFile.getProperty("username");
                String password = configFile.getProperty("password");
                String url = configFile.getProperty("url");
                String dbtype = configFile.getProperty("dbtype");
                Class.forName(dbtype);
                conn = DriverManager.getConnection(url, username, password); thanks in advance. ^^

    thank for the help mangst. i guess the IO approach is also applicable ^^; i changed my code to:
    configFile.load( new FileInputStream( ".\\resources\\config.properties" ) );but i had a little trouble in debugging it since it starts the file search from the main project directory. however it works fine upon deployment. ^^; thanks again.
    Edited by: xnofate on Sep 23, 2008 6:21 PM

Maybe you are looking for

  • ITunes crashes at startup

    Hello, Got a major issue here. Suddenly my iTunes crashes everytime at startup. First my specs and versions; iMac 27" 2.66 Ghz Intel Corei5 with 8 GB DDR3 Version 10.8 Mountain Lion iTunes version 10.6.3 iPhone 4 16 GB version 5.1.1 iPad 3 32 GB vers

  • MB5T background schedule ouput in alv format

    Hi all, Please help me to get MB5T report ouput of background schedule in ALV. I have put that report in bacground scheduling & the output of the same in BEST format but my client want the output in AlV format. Please suggest. Regards, Anant

  • Japanese mojibake in email created from Mac OS X Mail.  Help?

    Since Tiger I am having more and more Japanese friends of mine say that my email is turning up in their inbox as mojibake (junk characters.) I have found Article ID: 301986, "Mac OS X 10.4: Japanese message doesn't appear correctly in web mail or on

  • How to create a mapping with text file as my target

    I need to create a mapping with source as a table and target as a text file. I am using OWB 10g R2. with database Oracle10g. Any one can help me to create a mapping with a text file as target.

  • [SOLVEDipython 2 notebook: issue when using %matplotlib inline

    Hi, I have installed ipython2 on my Arch machine, but I am experiencing some issues with my matplotlib backend. At the beginning of a notebook I run: %matplotlib inline and then when I run %pylab the following error message appears: Using matplotlib