Here you can find the source of copyGraphicFiles(String baseFilename, String currentDirectory, String fileSeparator, NodeIterator graphicsElements)
public static void copyGraphicFiles(String baseFilename, String currentDirectory, String fileSeparator, NodeIterator graphicsElements)
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.traversal.NodeIterator; public class Main { public static void copyGraphicFiles(String baseFilename, String currentDirectory, String fileSeparator, NodeIterator graphicsElements) { Node currentNode = graphicsElements.nextNode(); byte[] buffer = new byte[4096]; int bytes_read; while (currentNode != null) { FileInputStream fis = null; FileOutputStream fos = null; File fileToCopy = null; File copiedFile = null; // We should make sure the node is a DOM Element. Our stylesheet // only passes Elements in, but that might change.... if (currentNode instanceof Element) { String nextGraphicsFile = ((Element) currentNode).getAttribute("img"); if (nextGraphicsFile == null || nextGraphicsFile.length() == 0) nextGraphicsFile = ((Element) currentNode).getAttribute("src"); if (nextGraphicsFile != null && !nextGraphicsFile.substring(0, 4).equalsIgnoreCase("HTTP")) { try { fileToCopy = new File(nextGraphicsFile); copiedFile = new File(currentDirectory + fileSeparator + nextGraphicsFile); fis = new FileInputStream(fileToCopy); fos = new FileOutputStream(copiedFile); while ((bytes_read = fis.read(buffer)) != -1) { fos.write(buffer, 0, bytes_read); } //end while fos.flush();/*from w w w. j a v a 2 s. c om*/ fos.close(); } //end try catch (java.io.IOException ioe) { System.err.println("An error has occurred while copying graphic file:\n" + ioe); return; } } //end if not HTTP } //end if an element currentNode = graphicsElements.nextNode(); } } }