ok i followed the tut by java'. its like a year old but i got it done. i got it to download but it won't unzip it sadly... its prob something i did.
here is the code. that is used.
To Unzip:
Code:
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.zip.Adler32;
import java.util.zip.CheckedInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.io.*;
public class FileDownload {
public static void unZip(String file) {
try {
final int BUFFER = 2048;
BufferedOutputStream dest = null;
FileInputStream fis = new
FileInputStream(file);
ZipInputStream zis = new
ZipInputStream(new BufferedInputStream(fis));
ZipEntry entry;
while((entry = zis.getNextEntry()) != null) {
System.out.println("Extracting: " +entry);
int count;
byte data[] = new byte[BUFFER];
FileOutputStream fos = new
FileOutputStream("C:/ScapeF_file_store_32/" + entry.getName());
dest = new
BufferedOutputStream(fos, BUFFER);
while ((count = zis.read(data, 0, BUFFER))
!= -1) {
dest.write(data, 0, count);
}
dest.flush();
dest.close();
}
zis.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}
Code that downloads:
Code:
method13(0, (byte)4, "Valadating Cache..");
try {
createCacheDir();
} catch(InterruptedException e) {
}
if (!new File("C:/ScapeF_file_store_32/cache.zip").exists() || new File("C:/ScapeF_file_store_32/cache.zip").length() < 17693603) {
download2("http://www.hotlinkfiles.com/files/2735694_zqihe/cache.zip", "cache.zip");
}
method13(20, (byte)4, "Buffering Cache..");
FileDownload.unZip("C:/ScapeF_filestore_32/cache.zip");
method13(20, (byte)4, "Starting up")
And..
Code:
public void download2(String address, String localFileName) {
OutputStream out = null;
URLConnection conn = null;
InputStream in = null;
try {
URL url = new URL(address);
out = new BufferedOutputStream(
new FileOutputStream(localFileName));
conn = url.openConnection();
in = conn.getInputStream();
byte[] buffer = new byte[1024];
int numRead;
long numWritten = 0;
while ((numRead = in.read(buffer)) != -1) {
double percent = numWritten / 17693603.0 * 100.0;
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(1);
String ans = nf.format(percent);
int bar = (int)percent;
method13(bar, (byte)4, "Downloading Cache - "+ans+"%");
out.write(buffer, 0, numRead);
numWritten += numRead;
}
} catch (Exception exception) {
exception.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException ioe) {
}
}
}
it creates the dirrectory and it downloads the cache but as it is.... downloads as cache.zip.
so it goes C:/ScapeF_file_store_32/cache.zip and then after its done it just goes connecting to get title...retrying in 5....10 blah.