View RSS Feed

cjburkey01

Download Script Weirdness

Rate this Entry
by , 02-21-2014 at 03:17 AM (1977 Views)
Quote Originally Posted by cjburkey01 View Post
So, I have this code:
Java Code:
public static final void downloadMods(String file, File folder) throws Exception {
	
	System.out.println("Doing " + file + " from " + "http://cjburkey.com/techpack/mods/" + file);
	System.out.println("Going to " + folder + "/Techpack/mods/" + file);
		JFrame frm=new JFrame();
		JProgressBar current = new JProgressBar(0, 100);
		current.setSize(50,50);
		current.setValue(0);
		current.setStringPainted(true);
		frm.add(current);
		frm.setLocationRelativeTo(null);
		frm.setVisible(true);
		frm.setLayout(new FlowLayout());
		frm.setSize(200, 50);
		frm.setDefaultCloseOperation(EXIT_ON_CLOSE);
		frm.setResizable(false);
		frm.setTitle(file);
		
		try {
			URL url=new URL("http://cjburkey.com/techpack/mods/" + file);
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
			int filesize = connection.getContentLength();
			float totalDataRead=0;
            java.io.BufferedInputStream in = new java.io.BufferedInputStream(connection.getInputStream());
            java.io.FileOutputStream fos = new java.io.FileOutputStream(folder + "/Techpack/mods/" + file);
            java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
            byte[] data = new byte[1024];
            int i=0;
            while((i=in.read(data,0,1024))>=0) {
            	totalDataRead=totalDataRead+i;
            	bout.write(data,0,i);
            	float Percent=(totalDataRead*100)/filesize;
            	current.setValue((int)Percent);
            }  
            bout.close();
            in.close();
            System.out.println("Done with " + file);
            frm.setVisible(false);
		} catch(Exception e) {
         javax.swing.JOptionPane.showConfirmDialog((java.awt.Component) null,e.getMessage() + " Not Found", "Error", javax.swing.JOptionPane.DEFAULT_OPTION);
		}
	}
and it doesn't work, but this one does:
Java Code:
public static final void downloadInstaller(File folder) throws Exception {
		
		String site="http://cjburkey.com/techpack/ForgeInstaller.jar";
		String filename = "";
		JFrame frm=new JFrame();
		JProgressBar current = new JProgressBar(0, 100);
		current.setSize(50,50);
		current.setValue(0);
		current.setStringPainted(true);
		frm.add(current);
		frm.setLocationRelativeTo(null);
		frm.setVisible(true);
		frm.setLayout(new FlowLayout());
		frm.setSize(200, 50);
		frm.setDefaultCloseOperation(EXIT_ON_CLOSE);
		frm.setResizable(false);
		frm.setTitle("ForgeInstaller.jar");
		
		filename = folder + "/Techpack/ForgeInstaller.jar";
		
		try {
			URL url=new URL(site);
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
			int filesize = connection.getContentLength();
			float totalDataRead=0;
            java.io.BufferedInputStream in = new java.io.BufferedInputStream(connection.getInputStream());
            java.io.FileOutputStream fos = new java.io.FileOutputStream(filename);
            java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
            byte[] data = new byte[1024];
            int i=0;
            while((i=in.read(data,0,1024))>=0) {
            	totalDataRead=totalDataRead+i;
            	bout.write(data,0,i);
            	float Percent=(totalDataRead*100)/filesize;
            	current.setValue((int)Percent);
            	System.out.println((int)Percent + "");
            }  
            bout.close();
            in.close();
            System.out.println("Done");
            frm.setVisible(false);
            javax.swing.JOptionPane.showConfirmDialog((java.awt.Component) null,"Download Successful!", "Success!", javax.swing.JOptionPane.DEFAULT_OPTION);
            Runtime.getRuntime().exec("java -jar " + folder + "/Techpack/ForgeInstaller.jar");
            System.exit(0);
		} catch(Exception e) {
         javax.swing.JOptionPane.showConfirmDialog((java.awt.Component) null,e.getMessage() + " Not Found", "Error", javax.swing.JOptionPane.DEFAULT_OPTION);
		}
	}
What is the difference and why does the first one give the /Users/CJ/Desktop/Techpack/mods/CodeChickenCore 1.3.3.3.jar(file doesn't exist) error? How would I fix this?
Zanele likes this.

Submit "Download Script Weirdness" to Facebook Submit "Download Script Weirdness" to Digg Submit "Download Script Weirdness" to del.icio.us Submit "Download Script Weirdness" to StumbleUpon Submit "Download Script Weirdness" to Google

Tags: None Add / Edit Tags
Categories
Uncategorized

Comments