本文整理汇总了Java中org.apache.commons.io.FileUtils.moveFile方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtils.moveFile方法的具体用法?Java FileUtils.moveFile怎么用?Java FileUtils.moveFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.FileUtils
的用法示例。
在下文中一共展示了FileUtils.moveFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: moveOutput
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public boolean moveOutput() {
File outputFile = null;
File targetFile = null;
try {
for (int i = 0; i < outputFiles.length; ++i) {
outputFile = outputFiles[i];
targetFile = targetFiles[i];
if (!outputFile.exists()) continue;
String outputFileAbsolute = removeThisDir(outputFile.getAbsolutePath());
String targetFileAbsolute = removeThisDir(targetFile.getAbsolutePath());
if (outputFileAbsolute.equals(targetFileAbsolute)) continue;
FileUtils.moveFile(outputFile, targetFile);
}
return true;
} catch (Exception e) {
fail("Failed to move " + outputFile.getAbsolutePath() + " to " + targetFile.getAbsolutePath(), e);
return false;
}
}
示例2: saveTmpFile
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private static State saveTmpFile(File tmpFile, String path) {
State state = null;
File targetFile = new File(path);
if (targetFile.canWrite()) {
return new BaseState(false, AppInfo.PERMISSION_DENIED);
}
try {
FileUtils.moveFile(tmpFile, targetFile);
} catch (IOException e) {
return new BaseState(false, AppInfo.IO_ERROR);
}
state = new BaseState(true);
state.putInfo("size", targetFile.length());
state.putInfo("title", targetFile.getName());
return state;
}
示例3: doTask
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@TaskAction
public void doTask() throws IOException, SigningException {
baseApkFile = getBaseApkFile();
destPath = getDestPath();
awoFile = getAwoFile();
zipAlign = getZipAlign();
outApkFile = getOutApkFile();
ZipUtils.addFileToZipFile(baseApkFile, outApkFile, awoFile, destPath, true);
File signFile = new File(outApkFile.getParent(), outApkFile.getName().replace(".apk", "-signed.apk"));
AtlasBuildContext.sBuilderAdapter.androidSigner.signFile(outApkFile, signFile, getSigningConfig());
if (null != zipAlign && zipAlign) {
File signAndZipAlignedFile = ZipAlignUtils.doZipAlign(androidBuilder, getProject(), signFile);
FileUtils.deleteQuietly(outApkFile);
FileUtils.moveFile(signAndZipAlignedFile, outApkFile);
}
}
示例4: saveFile
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
* The operation copies the file in the specified path.
* @param dirPath Target directory
* @param fileName File name
* @param srcFile
* @throws IOException
*/
public static void saveFile(String dirPath, String fileName, File srcFile)
throws IOException {
try {
File uploadPart = new File(dirPath, fileName);
if (uploadPart.exists()) {
uploadPart.delete();
}
FileUtils.moveFile(srcFile, uploadPart);
} catch (IOException ex) {
String prefix = "Save file error: '";
Logger.error(prefix + ex.getMessage() + "'");
throw new IOException(prefix + ex.getMessage() + "'");
}
}
示例5: saveTmpFile
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private static State saveTmpFile(File tmpFile, String path) {
File targetFile = new File(path);
if (targetFile.canWrite()) {
return new BaseState(false, AppInfo.PERMISSION_DENIED);
}
try {
FileUtils.moveFile(tmpFile, targetFile);
} catch (IOException e) {
return new BaseState(false, AppInfo.IO_ERROR);
}
State state = new BaseState(true);
state.putInfo("size", targetFile.length());
state.putInfo("title", targetFile.getName());
return state;
}
示例6: main
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
Thread.sleep(3000); //We wait a few seconds to allow the old instance to close so we can rename it without causing an exception
File oldJar = new File(args[0]);
File newJar = getTempFile(false);
File backupJar = new File(oldJar.getAbsolutePath() + ".old");
if (backupJar.exists()) {
backupJar.delete();
}
FileUtils.moveFile(oldJar, backupJar); //Backup the old jar so if things go wrong it can be manually reverted
FileUtils.copyFile(newJar, oldJar);
List<String> newArgs = new ArrayList<>();
newArgs.add("java");
newArgs.add("-jar");
newArgs.add(oldJar.getAbsolutePath()); //The old jar is now the new jar as we copyied it over
newArgs.add("-updateSuccess"); //Added here so we can show a dialog if when the new jar is opened
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command(newArgs);
processBuilder.start();
//Should close here
}
示例7: saveJobLog
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
* save job zip
*/
private File saveJobLog(Job job) {
Path jobPath = getJobLogPath(job);
Path zipPath = Paths.get(jobPath.getParent().toString(), job.getId().toString() + ".zip");
Path destPath = Paths.get(jobPath.toString(), job.getId().toString() + ".zip");
File folderFile = new File(jobPath.toString());
File zipFile = new File(zipPath.toString());
File destFile = new File(destPath.toString());
try {
ZipUtil.zipFolder(folderFile, zipFile);
FileUtils.moveFile(zipFile, destFile);
} catch (IOException e) {
throw new FlowException("save zip log error");
}
return destFile;
}
示例8: moveFile
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static void moveFile(File source, File destination) {
try {
FileUtils.moveFile(source, destination);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例9: fix
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public synchronized boolean fix(File file) throws IOException {
File tempFile = new File("temp.line-endings.txt");
if (fix(file, tempFile)) {
// file was changed
file.delete();
FileUtils.moveFile(tempFile, file);
tempFile.delete();
return true;
} else {
// no changes
tempFile.delete();
return false;
}
}
示例10: rewriteFile
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public synchronized boolean rewriteFile(File file, String encoding) throws IOException {
File tempFile = new File("temp.rewrite.txt");
if (rewriteFile(file, tempFile, encoding)) {
// file was changed
file.delete();
FileUtils.moveFile(tempFile, file);
tempFile.delete();
return true;
} else {
// no changes
tempFile.delete();
return false;
}
}
示例11: moveFile
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void moveFile(String currentAbsolutePath, String newAbsolutePath) throws BuenOjoFileException{
try {
FileUtils.moveFile(new File(currentAbsolutePath), new File(newAbsolutePath));
} catch (FileExistsException fe){
log.error(fe.getMessage());
throw new BuenOjoFileException("no se pudo mover el archivo: " +currentAbsolutePath+" al destino"+ newAbsolutePath + " porque ese archivo ya existe");
} catch (IOException e) {
log.error(e.getMessage());
throw new BuenOjoFileException("no se pudo mover el archivo: " +currentAbsolutePath+" al destino: "+ newAbsolutePath + e.getMessage());
}
}
示例12: takeFullScreenshot
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static void takeFullScreenshot(WebDriver webDriver, File pngFile, By... highlights)
throws IOException {
final PageSnapshot pageSnapshot = Shutterbug.shootPage(webDriver, BOTH_DIRECTIONS);
if (ArrayUtils.isNotEmpty(highlights)) {
Arrays.stream(highlights)
.map(webDriver::findElements)
.flatMap(Collection::stream)
.forEach(pageSnapshot::highlight);
}
FileUtils.forceMkdirParent(pngFile);
pageSnapshot.withName(pngFile.getName());
pageSnapshot.save(pngFile.getParent());
FileUtils.deleteQuietly(pngFile);
FileUtils.moveFile(new File(pngFile.getPath() + ".png"), pngFile);
}
示例13: writeFileToApk
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static void writeFileToApk(File destFile, File file, String path) throws IOException {
File outPutFile = new File(file.getParent(), "temp.apk");
ZipUtils.addFileToZipFile(file, outPutFile, destFile, path, true);
FileUtils.deleteQuietly(file);
FileUtils.moveFile(outPutFile, file);
FileUtils.deleteQuietly(destFile);
}
示例14: moveFile
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
* 移动文件
* @author Rocye
* @param srcPath 移动的源文件路径
* @param destPath 移动的目标文件路径
* @return true OR false
* @version 2017-02-28
*/
public static boolean moveFile(String srcPath, String destPath) {
try {
FileUtils.moveFile(new File(srcPath), new File(destPath));
return true;
} catch (IOException e) {
e.printStackTrace();
logger.error("调用ApacheCommon移动文件时:" + e.toString());
return false;
}
}
示例15: backupLog
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void backupLog() {
try {
File bkp = new File(LOG_BKP_LOC);
if (!bkp.exists()) {
bkp.mkdirs();
}
String filename = "log-" + Utility.getdatetimeString() + ".txt";
FileUtils.moveFile(new File(LOG_FILE), new File(bkp, filename));
} catch (IOException ex) {
java.util.logging.Logger.getLogger(UILogger.class.getName()).log(Level.SEVERE, null, ex);
}
}