简体   繁体   中英

Adding Multiple Files To A Jar File, Python

So, I made a downloader, that downloads a .zip file. Now, I would like to add the contents of that .zip file into the .jar file.

The .zip file contains : Folders, Pictures, Class Files

This is my downloader's code:

import urllib2
import os
import shutil
url = "https://dl.dropbox.com/u/29251693/CreeperCraft.zip"
file_name = url.split('/')[-1]
u = urllib2.urlopen(url)
f = open('c:\\users\\'+os.environ['USERNAME']+'\\CreeperCraft.zip', 'wb+')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading: %s Bytes: %s" % (file_name, file_size)
file_size_dl = 0
block_sz = 8192
while True:
    buffer = u.read(block_sz)
    if not buffer:
        break
    file_size_dl += len(buffer)
    f.write(buffer)
    status = r"%10d  [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
    status = status + chr(8)*(len(status)+1)
    print status,
f.close()

Can you tell me what to to, to make the content of the .zip file, go in the .jar ? If you are a good coder, can you supply me with the code? I would also like a progress bar thing like the one above while its addinf it, but that one, I got from internet, so I'm not sure how to code those myself.

Greets

.jar files are basically standard .zip files with a different ending, so you should be able to add files using the zipfile module.
http://docs.python.org/library/zipfile.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM