public static void changeUID(long oldUID,long newUID,String fromFile,String toFile) throws Exception {
  String inputFile;
  String tempFile;
  File file;
  String content;
  String line;
  BufferedReader reader;
  BufferedWriter writer;
  if (!isKOML(fromFile)) {
    inputFile=fromFile + ".koml";
    binaryToKOML(fromFile,inputFile);
  }
 else {
    inputFile=fromFile;
  }
  reader=new BufferedReader(new FileReader(inputFile));
  content="";
  while ((line=reader.readLine()) != null) {
    if (!content.equals(""))     content+="\n";
    content+=line;
  }
  reader.close();
  content=content.replaceAll(" uid='" + Long.toString(oldUID) + "'"," uid='" + Long.toString(newUID) + "'");
  tempFile=inputFile + ".temp";
  writer=new BufferedWriter(new FileWriter(tempFile));
  writer.write(content);
  writer.flush();
  writer.close();
  if (!isKOML(toFile)) {
    komlToBinary(tempFile,toFile);
  }
 else {
    writer=new BufferedWriter(new FileWriter(toFile));
    writer.write(content);
    writer.flush();
    writer.close();
  }
  file=new File(tempFile);
  file.delete();
}

public static void changeUID ( long oldUID , long newUID , String fromFile , String toFile ) throws Exception { String inputFile ; String tempFile ; File file ; String content ; String line ; BufferedReader reader ; BufferedWriter writer ; if ( ! isKOML ( fromFile ) ) { inputFile = fromFile + ".koml" ; binaryToKOML ( fromFile , inputFile ) ; } else { inputFile = fromFile ; } reader = new BufferedReader ( new FileReader ( inputFile ) ) ; content = "" ; while ( ( line = reader . readLine ( ) ) != null ) { if ( ! content . equals ( "" ) ) content += "\n" ; content += line ; } reader . close ( ) ; content = content . replaceAll ( " uid='" + Long . toString ( oldUID ) + "'" , " uid='" + Long . toString ( newUID ) + "'" ) ; tempFile = inputFile + ".temp" ; writer = new BufferedWriter ( new FileWriter ( tempFile ) ) ; writer . write ( content ) ; writer . flush ( ) ; writer . close ( ) ; if ( ! isKOML ( toFile ) ) { komlToBinary ( tempFile , toFile ) ; } else { writer = new BufferedWriter ( new FileWriter ( toFile ) ) ; writer . write ( content ) ; writer . flush ( ) ; writer . close ( ) ; } file = new File ( tempFile ) ; file . delete ( ) ; }
changes the olduid into newuid from the given file ( binary / koml ) into the other one ( binary / koml ) . it basically does a replace in the xml , i . e . it looks for " uid = ' olduid ' " and replaces it with " uid = ' newuid ' " .
