public boolean backup() throws IOException { if (!m_current.exists()) { return false; } copy(m_current, m_backup); return true; }
public boolean restore() throws IOException { if (!m_backup.exists()) { return false; } copy(m_backup, m_current); return true; }
/** * Helper function that writes the contents of one file to another. * @param source The source file. * @param destination The destination file. * @throws java.io.IOException Thrown when file IO goes wrong. */ private static void copy(File source, File destination) throws IOException { if (destination.exists()) { destination.delete(); } destination.createNewFile(); FileOutputStream out = new FileOutputStream(destination); FileInputStream in = new FileInputStream(source); copy(in, out); in.close(); out.close(); }
public void write(InputStream data) throws IOException { try { if (!m_current.exists()) { m_current.createNewFile(); } } catch (IOException e) { throw new IOException("Unable to create file:" + e.getMessage()); } try { FileOutputStream out = new FileOutputStream(m_current); copy(data, out); out.close(); } catch (FileNotFoundException e) { throw new IOException("Unable to open file:" + e.getMessage()); } }