您可以使用apache commons IO库。这很容易。我已经在许多项目中使用过它。
File dstFile = null;// check the directory for existence.String dstFolder = LOCAL_FILE.substring(0,LOCAL_FILE.lastIndexOf(File.separator));if(!(dstFolder.endsWith(File.separator) || dstFolder.endsWith("/"))) dstFolder += File.separator;// Creates the destination folder if doesn't not existsdstFile = new File(dstFolder);if (!dstFile.exists()) { dstFile.mkdirs();}try { URL url = new URL(URL_LOCATION); FileUtils.copyURLToFile(url, dstFile);} catch (Exception e) { System.err.println(e); VeBLogger.getInstance().log( e.getMessage());}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)