Created
February 18, 2013 12:00
-
-
Save stden/4976879 to your computer and use it in GitHub Desktop.
Замена ссылок на файлы содержимым файла
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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