I have a program that downloads .zip files to a folder on the computer. here is the code:

Java Code:
public static void fileDownload(String fAddress, String destinationDir, String name)
	{

		int slashIndex =fAddress.lastIndexOf('/');
		int periodIndex =fAddress.lastIndexOf('.');

		String fileName=fAddress.substring(periodIndex);
		fileName = name+fileName;

		if (periodIndex >=1 &&  slashIndex >= 0 && slashIndex < fAddress.length()-1)
		{
			fileUrl(fAddress,fileName,destinationDir);
		}
		else
		{
			System.err.println("path or file name.");
		}
	}
	
	public static String getFileName(String fAddress, String destinationDir, String name) {
		int slashIndex =fAddress.lastIndexOf('/');
		int periodIndex =fAddress.lastIndexOf('.');

		String fileName=fAddress.substring(periodIndex);
		fileName = name+fileName;

		if (periodIndex >=1 &&  slashIndex >= 0 && slashIndex < fAddress.length()-1)
		{
			return destinationDir+"/"+fileName;
		}
		else
		{
			System.err.println("path or file name.");
			return "";
		}
	}
It saves the files with the correct name in the correct location, but If I download a .zip with it, Then I try to unzip it, it just extracts "file_name.zip.cpgz" then when I unzip that It is apparently invalid. Other files like png's are fine, but archive files aren't working. Please help!

btw I know that the .zips are valid, because they work fine If I download them through my normal browser.