(1) Packaging jar method: Right-click the project name--export--jar file--Check the files that need to be packaged (by default)
(2) Do batch processing: write Start.bat, content such as:
Set Classpath=download.jar;commons-io-1.1.jar//The third-party jar is required here, and (1) the jar to be hit is specified, with a semicolon interval
Java FileSave//This is the class name that contains the main method
Pause
Add: The Business jar package needs to read the properties file, this path is relative to the root directory before packaging, after packaging, if not add the properties file in the Jar package, the properties file will not be found.
Therefore, it is best to put the package configuration file into the root directory of the project, after the jar, into the sibling directory.
Example: config.properties in the root directory
Import Java.io.file;import java.io.ioexception;import Java.net.url;import Java.util.properties;import Java.util.random;import Org.apache.commons.io.fileutils;public class filesave{static String Remoteurl = ""; static String Savefileurl = ""; static int threadnums = 0; public static void Main (string[] args) throws IOException {//Read config file readconfig (); for (int i = 0; i < threadnums; i++) {New Thread (new MyThread (Remoteurl, Savefileurl)). Start (); }} public static void Readconfig () throws IOException {String fp = system.getproperty ("User.dir") + File.separator + "Config.properties"; File File = new file (FP); Properties Properties = new properties (); Java.io.FileInputStream in = new Java.io.FileInputStream (file); Properties.load (in); In.close (); Remoteurl = Properties.getproperty ("Remoteurl"); Savefileurl = Properties.getproperty ("Savefileurl") + ":/download/"; Threadnums = Integer.parseint (Properties.getproperty ("threadnums")); }}class MyThread implements RUNNABLe{static Long NUM = 0; String Remoteurl = ""; String Savefileurl = ""; Public MyThread (String remoteurl, String savefileurl) {this.remoteurl = Remoteurl; This.savefileurl = Savefileurl; } public void Run () {Downloadfromurl (Remoteurl, Savefileurl);}/** * File Download method */public static String Downloadfromurl ( String url, string dir) {string fileName = ""; try {URL httpurl = new URL (URL); string[] US = url.split ("/"); FileName = Us[us.length-1]; String ramdom = System.currenttimemillis () + "" + New Random (). Nextint (+) + new Random (). Nextint (+) + new Rand Om (). Nextint (+) + getsequence (); filename = Ramdom + "_" + filename; SYSTEM.OUT.PRINTLN ("FileName:" + filename); File F = new file (dir + fileName); Fileutils.copyurltofile (Httpurl, F); } catch (Exception e) {e.printstacktrace (); return "fault!"; } return fileName; } public static synchronized long getsequence () {if (num > 100000000) {num = 0; } return num++; }}
Use Eclipse to make jar packages and do batch processing of bat