Skip to content

Instantly share code, notes, and snippets.

@stden
Created February 18, 2013 12:00
Show Gist options
  • Save stden/4976879 to your computer and use it in GitHub Desktop.
Save stden/4976879 to your computer and use it in GitHub Desktop.
Замена ссылок на файлы содержимым файла
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.Scanner;
/**
* Преобразование исходников
*/
public class CopySources {
public static void main(String[] args) throws IOException {
// Открываем заданных каталог
File baseDir = new File("C:\\wince\\cbposlib\\openssl");
for (File f : baseDir.listFiles()) {
Scanner scanner = new Scanner(f);
String line = scanner.nextLine();
if (line.startsWith("../../")) {
File fileFrom = new File("C:\\OpenSSL\\util\\pl\\" + line);
System.out.println(f.getAbsolutePath() + " " + fileFrom.exists());
copyFile(fileFrom, f);
}
}
}
/**
* Копирование файла
*
* @param sourceFile откуда копируем
* @param destFile куда копируем
* @throws IOException
*/
public static void copyFile(File sourceFile, File destFile) throws IOException {
if (!destFile.exists()) {
destFile.createNewFile();
}
FileChannel source = null;
FileChannel destination = null;
try {
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
destination.transferFrom(source, 0, source.size());
} finally {
if (source != null) {
source.close();
}
if (destination != null) {
destination.close();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment