Java根据URL下载文件

	public static void getURLResource(String ourputFile,String urlStr) throws Exception {

		URL resourceUrl = new URL(urlStr);
		HttpURLConnection con = (HttpURLConnection) resourceUrl.openConnection();
        DataInputStream reader = new DataInputStream(con.getInputStream());
        
        File f=new File(ourputFile);
        if(!f.getParentFile().exists()){
        	f.getParentFile().mkdir();
        }
        DataOutputStream writer = new DataOutputStream(new FileOutputStream(f));
        int ks = 0;
        while((ks = reader.read()) != -1) {
            writer.write(ks);
        }
        reader.close();
        writer.close();
	}

你可能感兴趣的:(java,F#)