Logo Search packages:      
Sourcecode: jlha-utils version File versions  Download package

String org::jlhafrontend::JLHAFrontEnd::mkbackup ( String  filename  )  [inline]

make a backup file (renaming a file to *.bak)

Parameters:
filename the name of the file need to rename to .bak
Returns:
the name of the backup file

Definition at line 318 of file JLHAFrontEnd.java.

References mylogger.

Referenced by add(), del(), and update().

                                            {
      String bakfilename=null;
      File fd=null;

      try {
          if (filename.length()>=4 && filename.charAt(filename.length()-4)=='.' && filename.substring(filename.length()-3).compareToIgnoreCase("bak")!=0) {
            bakfilename = filename.substring(0,filename.length()-3)+"bak";
          } else {
            bakfilename = filename+".bak";
          }
      } catch (IndexOutOfBoundsException e) {
          mylogger.severe("generate bakfilename error "+e.toString());
          return null;
      }

      try {
          fd=new File(bakfilename);
          if (fd.exists()) {
            fd.delete();
          }
      } catch (SecurityException e) {
          mylogger.info("delete old file error");
      }

      try {
          fd = new File(filename);
          if (fd.exists()) {
            fd.renameTo(new File(bakfilename));
          }
      } catch (SecurityException e) {
          mylogger.info("rename file");
      }
      return bakfilename;
    }


Generated by  Doxygen 1.6.0   Back to index