View Javadoc
1 package net.mlw.util; 2 3 import java.io.File; 4 import java.io.FileWriter; 5 import java.io.IOException; 6 import java.io.InputStream; 7 import java.net.URL; 8 9 import org.apache.commons.logging.Log; 10 import org.apache.commons.logging.LogFactory; 11 12 /*** 13 * @author Matthew L. Wilson 14 * @version $Revision: 1.4 $ $Date: 2004/03/17 14:20:21 $ 15 */ 16 public final class NetUtils 17 { 18 /*** Commons Logger */ 19 public static final Log LOGGER = LogFactory.getFactory().getInstance(NetUtils.class); 20 21 /*** Protect singleton. */ 22 private NetUtils() 23 { 24 25 } 26 27 /*** Retrieves a file. 28 * 29 * @param url The location of the file to retrieve. 30 * @param local The location to store the file locally. 31 * @throws IOException Thrown if thre is an issue saving the file. 32 */ 33 public static void copyFile(URL url, File local) throws IOException 34 { 35 InputStream in = null; 36 FileWriter writer = null; 37 38 try 39 { 40 writer = new FileWriter(local); 41 in = url.openStream(); 42 int c; 43 while ((c = in.read()) != -1) 44 { 45 writer.write(c); 46 } 47 } 48 finally 49 { 50 try 51 { 52 writer.flush(); 53 writer.close(); 54 in.close(); 55 } 56 catch (Exception ignore) 57 { 58 LOGGER.error(ignore); 59 } 60 } 61 62 } 63 64 }

This page was automatically generated by Maven