Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.File;

import java.io.IOException;

public class Main {
    private static File commit(String basename, File tmpFile) throws IOException {
        try {
            final String backupName = basename + "~";
            final File desired = new File(basename);
            final File backup = new File(backupName);
            backup.delete();
            if (desired.exists()) {
                if (!desired.renameTo(new File(backupName)))
                    throw new IOException("can't rename to " + backupName);
            }
            if (!tmpFile.renameTo(new File(basename)))
                throw new IOException("can't rename to " + basename);
        } catch (IOException x) {
            tmpFile.delete();
            throw x;
        }
        return new File(basename);
    }
}