How to compare and edit Resource bundle file using java programe

Hi All
I have two resource bundle with key, value and some comments. I need to write a java code to compare both of the values of the keys and if the values are different then i want to replace the second value with the first value.
Its a programe which will udpate the second file with the first file values.
I tried using Properties class but it didnt worked because when i am saving the file using store method it removes all the comments and the order of text also got disturbed.
How I need to do this any help appriciated.
Please elt me know if someone needs more info.
Thanks in advance.

Let's assume the ini file is a mapping type storage (key=value) so lets use Properties object. (works with java 1.4 & up)
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class Test {
     private static Properties props;
     public static void main(String[] args) throws IOException {
          File file = new File("test.ini");//This is out ini file
          props = new Properties();//Create the properties object
          read(file);//Read the ini file
          //Once we've populated the Properties object. set/add a property using the setProperty() method.
          props.setProperty("testing", "value");
          write(file);//Write to ini file
     public static void read(File file) throws IOException {
          FileInputStream fis = new FileInputStream(file);//Create a FileInputStream
          props.load(fis);//load the ini to the Properties file
          fis.close();//close
     public static void write(File file) throws IOException {
          FileOutputStream fos = new FileOutputStream(file);//Create a FileOutputStream
          props.store(fos, "");//write the Properties object values to our ini file
          fos.close();//close
}

Similar Messages

  • How to create and edit a .ini file using java

    Hi All...
    Pls help me in creating and editing an .ini file using java...
    thanks in advance
    Regards,
    sathya

    Let's assume the ini file is a mapping type storage (key=value) so lets use Properties object. (works with java 1.4 & up)
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Properties;
    public class Test {
         private static Properties props;
         public static void main(String[] args) throws IOException {
              File file = new File("test.ini");//This is out ini file
              props = new Properties();//Create the properties object
              read(file);//Read the ini file
              //Once we've populated the Properties object. set/add a property using the setProperty() method.
              props.setProperty("testing", "value");
              write(file);//Write to ini file
         public static void read(File file) throws IOException {
              FileInputStream fis = new FileInputStream(file);//Create a FileInputStream
              props.load(fis);//load the ini to the Properties file
              fis.close();//close
         public static void write(File file) throws IOException {
              FileOutputStream fos = new FileOutputStream(file);//Create a FileOutputStream
              props.store(fos, "");//write the Properties object values to our ini file
              fos.close();//close
    }

  • How to read the data from Excel file and Store in XML file using java

    Hi All,
    I got a problem with Excel file.
    My problem is how to read the data from Excel file and Store in XML file using java excel api.
    For getting the data from Excel file what are all the steps i need to follow to get the correct result.
    Any body can send me the code (with java code ,Excel sheet) to this mail id : [email protected]
    Thanks & Regards,
    Sreenu,
    [email protected],
    india,

    If you want someone to do your work, please have the courtesy to provide payment.
    http://www.rentacoder.com

  • Zip and extract multiple files using java program

    how can i zip and extract multiple files using java program.

    Hi,
    Look into the java.util.zip and java.util.jar they expose methods to manipulate zip and jar files.

  • How to create a table in the file using java code.?

    HI,
    I should export the data from the view objects to a word document. I have done that but I should
    display the data in the form of a table.
    Kindly come up with the necessary information on how to create a table in the file using java.
    Thanks,
    Phani

    Hi, Thank you for responding to my query.
    The below are the details of my code.
    DCBindingContainer dcBindings =
    (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    DCIteratorBinding StudentDetailsContent =
    (DCIteratorBinding)dcBindings.get("StudentView1Iterator");
    OutputStreamWriter w = new OutputStreamWriter(outputStream, "UTF-8");
    Row currentRow =
    StudentDetailsContent.getRowSetIterator().first();
    Object a[]= currentRow.getAttributeValues();
    int i;
    for(i=0 ;i<=a.length;i++){
    w.write(a.toString());
    w.write(" ");
    w.flush();
    I am usning this coding to achieve the task of exporting data to file.
    I need to display this information in the table that is where I need help from you people.
    Thanks,

  • How to uncompress zip files using java program

    hai,
    please give some sample code to decompress the zip file.
    how to uncompress zip files using java program
    thanking you
    arivarasu

    http://developer.java.sun.com/developer/technicalArticles/Programming/PerfTuning/
    Scroll down to 'Compression'

  • How to store a data on txt file through java program

    that means i want a coding for write data on txt file using java program.that storing data is stored like this formate,
    sathees
    krishnan
    rama
    suresh
    Stored on one by one. not like this
    sathees krishnan rama suresh.........

    import java.io.*;
    import org.w3c.dom.Document;
    import org.w3c.dom.*;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    public class rsk1{
    public static void main (String argv []){
    try {
    String sr[] = new String[100];
                   String s1=" ";
                   int j=0;
                   DataInputStream in = new DataInputStream(System.in);
                   OutputStream f1 = new FileOutputStream("file1.txt");
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    Document doc = docBuilder.parse (new File("book.xml"));
    // normalize text representation
    doc.getDocumentElement ().normalize ();
    System.out.println ("Root element of the doc is " +
    doc.getDocumentElement().getNodeName());
    NodeList listOfPersons = doc.getElementsByTagName("person");
    int totalPersons = listOfPersons.getLength();
    System.out.println("Total no of people : " + totalPersons);
    for(int s=0; s<listOfPersons.getLength() ; s++){
    Node firstPersonNode = listOfPersons.item(s);
    if(firstPersonNode.getNodeType() == Node.ELEMENT_NODE){
    Element firstPersonElement = (Element)firstPersonNode;
    NodeList firstNameList = firstPersonElement.getElementsByTagName("first");
    Element firstNameElement = (Element)firstNameList.item(0);
    NodeList textFNList = firstNameElement.getChildNodes();
    sr[++j]=((Node)textFNList.item(0)).getNodeValue().trim();
    NodeList lastNameList = firstPersonElement.getElementsByTagName("last");
    Element lastNameElement = (Element)lastNameList.item(0);
    NodeList textLNList = lastNameElement.getChildNodes();
    sr[++j]=((Node)textLNList.item(0)).getNodeValue().trim();
    NodeList ageList = firstPersonElement.getElementsByTagName("age");
    Element ageElement = (Element)ageList.item(0);
    NodeList textAgeList = ageElement.getChildNodes();
    sr[++j]=((Node)textAgeList.item(0)).getNodeValue().trim();
    NodeList stuList = firstPersonElement.getElementsByTagName("stu");
    Element stuElement = (Element)stuList.item(0);
    NodeList textstuList = stuElement.getChildNodes();
    sr[++j]=((Node)textstuList.item(0)).getNodeValue().trim();
    }//end of if clause
    }//end of for loop with s var
    System.out.println("Process completed");
    for(int i=1;i<=j;i++)
                   byte buf[] = sr.getBytes();
                                       byte buf1[] = s1.getBytes();
         f1.write(buf);
                                       f1.write(buf1);
    f1.close();
    }catch (SAXParseException err) {
    System.out.println ("** Parsing error" + ", line "
    + err.getLineNumber () + ", uri " + err.getSystemId ());
    System.out.println(" " + err.getMessage ());
    }catch (SAXException e) {
    Exception x = e.getException ();
    ((x == null) ? e : x).printStackTrace ();
    }catch (Throwable t) {
    t.printStackTrace ();
    }//end of main

  • How to store grid points in a file using Java Swing?

    Please someone help me with any suggestions about how to store the grid points in a file using Java Swing

    Actually i have designed a gridlayout in Java Swing and have added some components to it such as buttons or images....My problem is when I click on any of the cell of the grid,the corresponding cell number should be stored in an external file....Do u have any suggestions on how to do it?

  • How to Write in bold to a file using java I/O classes?

    Hi,
    Using I/O classes I want to prepare a .doc file in which some text will be there. I want that text to be formatted. Like some text I want to be bold. Some text to be italic. How can I write bold/Italic text to the file using java I/O classes.
    Thanks
    Prashant

    By .doc file, I'm assuming you mean an MS Word document, yes? (fyi, Word Perfect also used the .doc extension)
    The .doc format is proprietary to Microsoft and isn't documented by them. In order to output a file in .doc format you'd have to understand that format correctly, otherwise MS Word will spit out it's tongue at you, call you names, and maybe send the Microsoft Police to "audit" your PC Software Licensing.
    Fortunately for you there is an open source project to demangle the microsoft file formats. See http://jakarta.apache.org/poi/ and especially pay attention to the HDF project (Horrible Document Format).
    - David

  • Create shortcut file using Java program

    Hi,
    I have an exe file. I want to create its shortcut file through Java program.
    Is it possible? If yes, how to do it??
    regards,
    Anand

    Hi,
    See we have developed a swing application for the school children.
    Also, we have written Java based installer program to install that software.
    This installer program asks user whether he wants to create a desktop shortcut or not.
    Now I am not getting how to write Java program to create a desktop shortcut of our software.
    So, can somebody help us in this problem??
    regards,
    Anand

  • How to get free disk space in linux   Using JAVA program ?

    Hi,
    I am new to such adavance topics.. like JNI
    I have to check linux system free disk space , if space is more than 80% it should email to user.
    But how to check that Using Java program ??
    can u give me one sample example ? i will do it if u can do some for me
    thanks
    give me possible solutions...

    Using the Runtime class you can execute any linux command. Check it out.

  • How to find and edit an .htaccess file?

    I trying to set up a podcast/blog in WordPress, and I need to edit an .htaccess file.
    I use Fetch as my FTP client to access my web site's hosting account, and I can see that there's an .htaccess file there. I need to get it and add a couple lines of code to it to do a URL redirect.
    When I use Fetch to "Get" it, it appears to download okay, but then I can't see it on my desktop or doing a search. I just downloaded EasyFind, on the advice given in another thread, but now I'm wondering, even if I can find the thing, whether I'm going to be able to edit it.
    Anybody got experience with this?
    Dave

    After I posted my inquiry, I solved the problem. Here it is, step-by-step, for somebody wanting a simple solution:
    1. Download EasyFind from this location: http://www.versiontracker.com/dyn/moreinfo/macosx/11706
    2. Launch EasyFind; make sure the option to show hidden files is checked on; and then search for .htaccess. It should show up in a list of all hidden files in wherever you're looking (Desktop or wherever).
    3. I double-clicked on .htaccess in EasyFind, and this opened the file in TextEdit. I edited the .htaccess file by adding the command info I needed (in my case, a redirect command). Then I did a simple "Save" command (not Save As...). This saved the edited version as .htaccess (hidden).
    4. I launched Fetch, and clicked "Put." In the Put dialog box, there's an option to show hidden files. When I checked that on, there was .htaccess, visible in the list. I selected that and FTPed it to my web server account.
    5. I tested the redirect, and it worked like a charm!
    Thanks very much to Matt Baya for talking me through some of this, including how to change the .htaccess to do my redirect.
    Dave

  • How to upload and edit an eps file

    Hi all,
    I have just downloaded an eps file from shutterstock and they given me this free trial idea with adobe but unfortunately i have got no idea how to upload my file and edit it and save it as a jpg file for further work. can anyone help me please

    you can use adobe illustrator to open that file.

  • Java and XML :: Unlocking, editing and locking an XML file using JAVA

    I need to develop a form with Address field , When i enter address information and submit the form it needs to generate an
    XML file for furthur processing.
    Now my problem is :
    When i want to edit the address....after submitting the form by entering the address information, it should unlock
    the XML and edit the XML and then lock it.
    How can i achive programatically, unlocking an XML file, editing the file, and locking it?.
    Thanks,
    Maruthi.

    There's a FileLock class, you know, in the java.nio.channels package. However before you start using it you should read its API documentation carefully including statements like " Whether or not a lock actually prevents another program from accessing the content of the locked region is system-dependent and therefore unspecified".
    Personally I would say that if you need to synchronize access to this XML file, you should consider changing your design to use something that supports locking a bit better, like a database. Or by writing a server that encapsulates the XML file and accepts requests to read it and update it, serializing those requests appropriately.

  • How to ZIP the files and folders/sub folder files using java

    HI All,
    I'm New to this Forum, Could anybody tell me how to zip the files and folders/sub folders using java. For example I have a folder with the name testfolder and side that folder I have some files and some sub folders inside subfolders I have some other files. I need to ZIP the files and folders as they are in same hierarchy.
    Any pointers or help wolud be appritiated.
    Thanks,
    Rajeshbabu V

    [http://www.devx.com/tips/Tip/14049]

Maybe you are looking for

  • Can I use a PC drive to upgrade my macbook pro

    My CD/DVD drive on the macbook pro is dead.  I want to upgrade to 10.6.  Can I use my shared CD from my PC (win7) to install 10.6 on the MBP?

  • 10.5.8 updated killed Write/Update permissions on my Boot camp partition.

    I can't figure this one out. I regularly "reach over" to my boot camp partition to move files from XP to my mac, and have automator scripts that also do that. Since the update, it no longer works either manually or via automator. I can read and copy

  • Output type - Special function 8 - ARCHIV_CONNECTION_INSERT

    Hi gurus, I created a new Output Type with special function 8 called ZPDF in transaction NACE with application MR (invoice verification) and I added to that Output Type ZPDF our custom program called ZXXX_ARCHIVE_LINK in order to post into the MM inv

  • How to do search with LOV+oracle adf

    Hi, I m using jdeveloper 11g with oracle adf .As i know that input text with LOV has default search facility. Plz tell me how to make search by using LOV .so that when i click on input text with LOV data should come in form.

  • Mapping concepts

    Hi all,         Can any one give me the detailed and separate blogs for context handling, value mapping, user defined functions, and multi mapping. Thanks in Advance