/** * Copies the specified source file to the specified destination file. If the destination file does not exist, * it is created. * * @param src The source file name. * @param dst The destination file name. * @throws IOException if there is an issue copying the file */ public static void copyCheckedEx(File src, File dst) throws IOException { InputStream in = new FileInputStream(src); copy(in, dst); }
public static boolean deleteFile(String filePath) { return delete(new File(filePath), false); }
/** * Copies the specified source file to the specified destintaion file. If the destinationst file does not exist, * it is created. * * @param src The source file name. * @param dst The destination file name. */ public static void copy(File src, File dst) { try { copyCheckedEx(src, dst); } catch (IOException e) { throw new RuntimeException(e); } }
copy(source, dst); copy(file, new File(dst.toString() + File.separator + file.getName())); copyRecursive(file, new File(dst + File.separator + file.getName()));
/** * Reads a text file as a string. * * @param filename The name of the file. * * @return The contents of the file. */ public static byte[] readFileAsBytes(String filename) { try(BufferedInputStream is = new BufferedInputStream(new FileInputStream(filename))) { return readStreamAsString(is); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Reads a text file as a string. * * @param filename The name of the file. * * @return The contents of the file. */ public static String readFileAsString(String filename) { return new String(readFileAsBytes(filename)); }
/** * Reads a text file as a string. * * @param file The file. * * @return The contents of the file. */ public static String readFileAsString(File file) { try(BufferedInputStream is = new BufferedInputStream(new FileInputStream(file))) { return new String(readStreamAsString(is)); } catch (IOException e) { throw new RuntimeException(e); } }
public static boolean deleteDirectory(String directoryPath) { File directory = new File(directoryPath); if (directory.isDirectory()) { if (directory.listFiles().length == 0) { return delete(directory, true); } } return false; }
FileUtils.copy(in, destinationFile);
@Override protected void doDelete() { if (_storePath != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Deleting preference store " + _storePath); } File preferenceStoreFile = new File(_storePath); if (!FileUtils.delete(preferenceStoreFile, true)) { LOGGER.info("Failed to delete the preference store at location " + _storePath); } } }
FileUtils.copy(sourceFile, destFile);
protected void delete(final String storePath) { if (storePath != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Deleting store " + storePath); } File configFile = new File(storePath); if (!FileUtils.delete(configFile, true)) { LOGGER.info("Failed to delete the store at location " + storePath); } } _configFileName = null; _directoryName = null; } }
@Override public void onDelete(ConfiguredObject<?> parent) { FileBasedSettings fileBasedSettings = (FileBasedSettings)parent; String storePath = fileBasedSettings.getStorePath(); if (storePath != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Deleting store " + storePath); } File configFile = new File(storePath); if (!FileUtils.delete(configFile, true)) { LOGGER.info("Failed to delete the store at location " + storePath); } } }
@Override public void onDelete(ConfiguredObject parent) { if (isMessageStoreOpen()) { throw new IllegalStateException("Cannot delete the store as store is still open"); } FileBasedSettings fileBasedSettings = (FileBasedSettings)parent; String storePath = fileBasedSettings.getStorePath(); if (storePath != null) { LOGGER.debug("Deleting store : {}", storePath); File configFile = new File(storePath); if (!FileUtils.delete(configFile, true)) { LOGGER.info("Failed to delete the store at location : {}", storePath); } } }
@Override public void onDelete(ConfiguredObject<?> parent) { if (isMessageStoreOpen()) { throw new IllegalStateException("Cannot delete the store as store is still open"); } FileBasedSettings fileBasedSettings = (FileBasedSettings)parent; String storePath = fileBasedSettings.getStorePath(); if (storePath != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Deleting store : {}", storePath); } File configFile = new File(storePath); if (!FileUtils.delete(configFile, true)) { LOGGER.info("Failed to delete the store at location : {} ", storePath); } } }
@Override public void onDelete(ConfiguredObject<?> parent) { if (_providedMessageStore.isMessageStoreOpen()) { throw new IllegalStateException("Cannot delete the store as the provided message store is still open"); } FileBasedSettings fileBasedSettings = (FileBasedSettings) parent; String storePath = fileBasedSettings.getStorePath(); if (!DerbyUtils.MEMORY_STORE_LOCATION.equals(storePath)) { if (storePath != null) { LOGGER.debug("Deleting store {}", storePath); File configFile = new File(storePath); if (!FileUtils.delete(configFile, true)) { LOGGER.info("Failed to delete the store at location " + storePath); } } } }
success = delete(files[i], true) && success;