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
}

Similar Messages

  • 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
    }

  • 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,

  • Create and edit a PDF file

    Hi,
    Still very new on the Mac - how do I create and edit a pdf file on my iMac?
    Thanks for any info.

    Creating a PDF is really simple. From any application choose the print command (Command P) and in the lower left of the box you will see PDF, click PDF and then choose what you want to do. It will look similar to:
    For editing PDF files you can do some basic annotation editing using the Preview app which you will find in your Applications folder. However if you want to do more sophisticated editing then you will need to purchase an editor from the Mac App Store. Open the store type PDF Editor in the search field and you will find quite a few to choose from ranging from $2.99 to $99.99 depending on your needs.

  • How to create and manage the log file

    Hi,
    I want to trace and debug the program process.
    I write the code for creating log file and debugging the process.
    But i am not able get the result.
    please help me how to create and manage the log file.
    Here i post sample program
    package Src;
    import java.io.*;
    import org.apache.log4j.*;
    import java.util.logging.FileHandler;
    public class Mylog
         private static final Logger log = Logger.getLogger("Mylog.class");
         public static void main(String[] args) throws Exception {
         try {
           // Create an appending file handler
            boolean append = true;
            FileHandler handler = new FileHandler("debug.log", append);
            // Add to the desired logger
            Logger logger = Logger.getLogger("com.mycompany");
            System.out.println("after creating log file");     
              catch (IOException e)
                   System.out.println("Sys Err");
            }Please give the your valuable suggesstion... !
    Thanks
    MerlinRoshina

    Just i need to write a single line in log file.

  • How to create and edit anomalous tables in DIAdem? Such as the example list.

    How to create and edit anomalous tables in DIAdem?
    Can the tables  be edited as in MS Word?
    帖子被yangafreet在08-21-2007 10:28 PM时编辑过了
    Attachments:
    table example.doc ‏26 KB

    Hi yangafreet,
    There is no way I know of to create a DIAdem table that looks like the table in your Word document.
    Brad Turpin
    DIAdem Product Support Engineer
    National Instruments

  • 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

  • How to create and call a COM component in Java

    Hi All,
    can you suggest how to create and call a COM component..or if have any sample simple application can you send it to me...i will try to develop my project.
    actually i am configuring a OCR Engine using SDK which is in VB .Net when i contacted their support they told that if i have any sample COM based component Project they will help me...
    So please can you help in this.
    Thanks in advance.

    As said by my fellow posters Java Devolopment Environment (Except Microsoft implementation of JVM,this is no longer supported by MS themseleves) does not provide an built-in support to serve this cause.
    If you are looking to devolop a custom based solution the below is a good place to start with where end user is talking about Java <=> JNI <=> Native <=> COM connectivity.
    [http://bloggershetty.blogspot.com/2004/12/java-jni-com-activex-bridge-lots-of.html]
    However,if you are looking for ready made solutions ?
    Implementation any one of the solutions stated below might serve your cause.
    Open Source Solutions:
    [http://j-interop.org/]
    [http://www.danadler.com/jacob/]
    Commercial Solutions:
    [http://javacombridge.com/]
    [http://www.jnbridge.com/]
    [http://www.nevaobject.com/j2cdetails.asp?kw=java%20com%20bridge]
    [http://j-integra.intrinsyc.com/]
    Hope this might help :)
    REGARDS,
    RaHuL

  • 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

  • How to create a mail user agent by using JAVA...

    my lecturer has asked me to create a mail user agent by using JAVA , i have no idea how to start this assignment......

    What part are you stuck on? Creating a GUI (look at the Swing tutorials), or writing the talk-to-mail-server bit? Look at Java Mail, or the email RFCs.

  • 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.

  • How to create and write in a file

    Hello Gurus,
    I am creating a file based on the date and time and writing into that. But, I am still getting exception error and all. Kindly, please let me know.
    thanks for all the help...j
    Error:-
    C:\Usage\JavaFiles>java filename "abc"
    Exception in thread "main" java.io.FileNotFoundException:Detail09-2003-
    03:28:04.doc (The system cannot find the file specified)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:176)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
    at TowerDetail.main(TowerDetail.java:30)
    Code sample:-
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    import java.sql.*;
    import java.text.*;
    public class TowerDetail{
    public static void main (String[] args) throws IOException{
    String userName = "user";
    String passwd = "pwd";
    String con_db = "jdbc:odbc:datasource";
    String ssn = args[0];
    Vector results = new Vector();
    Connection con = null;
    CallableStatement cstmt = null;
    java.util.TimeZone tz = java.util.TimeZone.getTimeZone("EST");
    java.util.Date now = new java.util.Date();
    DateFormat df = new SimpleDateFormat("MM-dd-yyyy-hh:mm:ss");
    df.setTimeZone(tz);
    String result = df.format(now);
    String fileName = "Detail"+result+".doc";
    File inputFile = new File(fileName);
    FileOutputStream fos = new FileOutputStream(inputFile);
    PrintWriter pw = new PrintWriter(fos);
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }catch (Exception e) {
    System.out.println("JDBC Error: "+e.getMessage());
    return;
    try{
    con = DriverManager.getConnection(con_db, userName, passwd);
    cstmt = con.prepareCall("{call dbo.sp_usage_detail(?)}");
    cstmt.setString(1, ssn.trim());
    ResultSet rs = cstmt.executeQuery();
    pw.println("Report "+result);
    pw.println("------------------------------------------------------------------------------------
    while(rs.next()){
    .... write in the file...
    pw.println("------------------------------------------------------------------------------------
    pw.close();
    System.out.println("Your file Detail"+result+".doc is ready!!!");
    cstmt.close();
    con.close();
    }catch(SQLException ex){
    System.out.println("SQLException: ");
    System.out.println(ex.getMessage());
    }catch(NullPointerException e){
    System.out.println("Null Pointer Exception: ");
    System.out.println(e.getMessage());

    Now, I got out of the command prompt and reentered. I didn't set any classpath or anything. I have created a subdir \archive in the C:\ and writing an output file [DetailTower.....doc")into that.
    The DetailTower.class is in C:\Detail\ProjectClass dirctory.
    Now at,
    C:\Detail\ProjectClass\java -classpath . DetailTower "abc"
    I am getting this error:-
    C:\Detail\ProjectClass>java -classpath . DetailTower "999999"
    Exception in thread "main" java.io.FileNotFoundException: c:\archive\DetailTower09-10-2003-06:23:40.doc (The system cannot find the file specified)at java.io.FileOutputStream.open(Native Method)
            at java.io.FileOutputStream.<init>(FileOutputStream.java:176)
            at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
            at Detail.main(DetailTower.java:32)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to create and handle a text file in CVI

    Is there any way to create and handle (like...open,write,read,truncate,close)  the .txt file in CVI?

    Sure. CVI is a regular C compiler and hence you can use all ANSI C functions. In addition you can use the File I/O functions from the utility library.

Maybe you are looking for

  • Livecycle Designer 7.0 - How do I link a text box in a form to a radio button or checkbox?

    Hello, I am using Livecycle Designer 7.0 to create a form. I have a scenario where I have several options on a question where they choose one radio button. The last option of the radio button has a text box accompanying it and I only want it to be ab

  • Error message for itunes version 9

    I can expect quite a few people have had problems with the new version of itunes, but I wonder if anybody has any other suggestions than I have already tried. I keep getting an error message come up every single time I insert a cd into the drive so t

  • ICloud Lion $29.99 MS Office 2004 not supported $$$

    Holy Crap!  I joined iCloud feeling the clock ticking.  Then I learn I need the $29.99 OS upgrade to Lion to support iCloud and I oblige.  NOW, I learn MS Office 2004 is not supported!  Feeling a little baited here.  Can't open any of my .doc's!  Any

  • OSB and SOA Suite on same home

    Hi, Which version of Oracle Service Bus can be installed on existing middleware home? The target platform is - Oracle SOA Suite + Oracle service Bus. My assumption is it should be possible to "share" same m/w home (WLS10.3.5) between SOA Suite and OS

  • Backup - how to restore the entire configuration (system cloning)

    Hi, is it possible to backup the entire system configuration on order to restore file and system configuration? Time machine is a file backup, if I reset yosemite I've to configure the entire operative system...