Is there a way out of this?

Hi,
I am facing a BIG problem. And ofcourse that is why I am posting a topic here, as you Gurus always help out someone like me in trouble. Ok now to the main topic....
I have got a class called config (extends Serializable). Which stores all the configuration details. It is stored to a file on the disk as to store the configuration details. Now when ever I change the config.java file the signature and other details of the class file is changed a little. (Please let me know what changes could and could not change the signature of the class)
And this makes the application's text file (where the config.class was written to) useless as it has different version of class in it. This happens even if I change just the package of the config class.
Is there a way out of it? Do I have to create a bridge class everytime I update anything in config class?
What could be someother ways to store a configuration file? I am trying to learn XML for it right now but this will be a long process for me to get this out of it. And will there be this problem of bridging all the time, between two different versions or not if I use XML?
Please reply for both the solutions Serializable as well as XML (and/or anyother solution you may have).
Thanks a lot in advance.
Ri

Okay here it is.
Hope you find it useful. If you need any help just email me.
package com.wp.io;
import com.wp.util.Dbg;
import java.io.*;
import java.util.StringTokenizer;
import java.util.*;
* New file type for parameter loading and text loading.
* Assume that if this code destroys your computer, I
* wont be held responsible and may actually find it amusing.
* Creation date: (30/01/2003 5:12:47 PM)
* @author: [email protected]
public class JFile extends File
    InputStream in;
    java.util.StringTokenizer st = null;
    Object object;
     * JFile constructor comment.
     * @param parent java.io.File
     * @param child java.lang.String
    public JFile(File parent, String child)
        super(parent, child);
     * JFile constructor comment.
     * @param pathname java.lang.String
    public JFile(String pathname)
        super(pathname);
     * JFile constructor comment.
     * @param parent java.lang.String
     * @param child java.lang.String
    public JFile(String parent, String child)
        super(parent, child);
     * Load in this file as a string
     * @return String This File.
    public String loadText()
        if (!exists())
            return null;
        try
            byte[] p = new byte[(int) length()];
            InputStream in = new FileInputStream(this);
            in.read(p);
            in.close();
            return new String(p);
        catch (Exception e)
            Dbg.printWarning("Could not load in File:\n\t");
            return null;
     * If this file can be represented as an object input stream,
     * and is not currently being read in it can
     * be read in as an objct stream
     * @return boolean If there are objects to read in
    public boolean hasMoreObjects()
        try
            if (in == null)
                in = new ObjectInputStream(in);
            object = ((ObjectInputStream) in).readObject();
            if (object == null)
                in.close();
                in = null;
        catch (Exception e)
            in = null;
            Dbg.printError("Error in hasMoreObjects():\n\t");
        return object != null;
     * Return the current object from this file stream.
     * @return java.lang.Object
    public Object nextObject()
        return object;
     * If this file can be represented as a string,
     * and is not currently being read in it can
     * be read in as an delimited string
     * @return boolean If there are strings to read in
    public boolean hasMoreTokens(String delimit)
        if (st == null)
            st = new java.util.StringTokenizer(loadText(), delimit);
        return st.hasMoreTokens();
     * Return the current object from this file stream.
     * @return java.lang.Object
    public String nextToken()
        return st.nextToken();
     * Copies the file to the destination
     * @param pPath java.lang.String
    public void copyTo(String pPath) throws IOException
        OutputStream out = new FileOutputStream(pPath);
        InputStream in = new FileInputStream(this);
        byte[] buffer = new byte[1024];
        int len;
        while ((len = in.read(buffer)) >= 0)
            out.write(buffer, 0, len);
        in.close();
        out.close();
     * Overwrite the List() method to return JFiles
     * @param pFileFilter FileFilter The template to match files.
     * @return JFile[] a List of matching JFiles
    public JFile[] listJFiles(FilenameFilter pFileFilter)
        File[] files = super.listFiles(pFileFilter);
        if (files == null)
            return null;
        JFile[] jFiles = new JFile[files.length];
        for (int i = 0; jFiles != null && i < jFiles.length; i++)
            jFiles[i] = new JFile(files.getAbsolutePath());
return jFiles;
* Populate a hashtable from a file.
* For example, a file that reads
* param1, param1value
* param2, param2value
* param3, param3value
* param4, param4value
* would be read in using the command
* Hashtable configoration = myJFile.parametersLoad("\n", ", ");
* @return java.util.Hashtable
* @param paramDelimiter java.lang.String the delimiter that seperates parameters (I use \n for more readability)
* @param ValueDelimiter java.lang.String The delimiter that seperates the param name from the value
public Hashtable parametersLoad(
String paramDelimiter,
String valueDelimiter)
Hashtable memory = new Hashtable();
if (!exists())
return new Hashtable();
String line = "";
while (hasMoreTokens(paramDelimiter))
line = nextToken();
int sp = line.indexOf(valueDelimiter);
memory.put(line.substring(0, sp), line.substring(sp + 1));
return memory;
* Save from a hashtable to a file.
* @param source java.util.Hashtable
* @param paramDelimiter java.lang.String How to seperate the params in the file. eg "\n"
* @param valueDelimiter java.lang.String String to seperate the param from the value. eg. ","
public void parametersSave(
Hashtable source,
String paramDelimiter,
String valueDelimiter)
String output = "";
Enumeration keys = source.keys();
String key = "";
while (keys.hasMoreElements())
key = (String) keys.nextElement();
output += key + valueDelimiter + source.get(keys) + paramDelimiter;
try
DataOutputStream out =
new DataOutputStream(new FileOutputStream(this));
out.writeBytes(output);
out.close();
catch (Exception e)
Dbg.printError(e);
and this is the debug class which you don't need but will need if you don't want to have to modify JFile.
package com.wp.util;
* So you can override the printing if need be from one central location.
* Creation date: (30/01/2003 5:22:37 PM)
* @author: [email protected]
public class Dbg
    public static final int WARNING = 1;
    public static void printError(Object e)
        System.out.print(e);
    public static void printWarning(String g)
        System.out.print(g);
    public static void printInformation(String g)
        System.out.print(g);
    public static void printDebug(String string)
        System.out.print(string);

Similar Messages

Maybe you are looking for