View RSS Feed

cjburkey01

Download Script Weirdness

Rate this Entry
by , 02-21-2014 at 03:17 AM (2142 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

  1. afitnesswx's Avatar
    • |
    • permalink
    plank workout routine for abs and chest side plank exercise progression
    It is not only efficient in making your tummy muscles strong, but also great for your back. If you dislike going to the gym, allow yourself the liberty of not going there. It is hence important for all to seek professional help in ascertaining their fitness objectives and know how you can get them best. There is believed that a connection exists between restorative yoga and obesity. It will help you maintain a healthier lifestyle, and spend time with family. Vary these exercises and practice them regularly at least for 30 minutes. Its Not Just Exercising
    Home - fitnessmaxinfo's website
    However, of late, it has gained particular attention from Hollywood celebrities. ? Work Out at Work: Find out time at office to work out. Squeeze the Butt and Abs before Coming Upwards: A common cheat mechanism in the upward part of the pushup is to arch the lower back, elongate the abs and drop the tummy on the floor. During other times, physical fitness is something that requires simple exercising methods such as walking around the neighborhood or running errands with tasks like swimming, hiking or biking. Practice stretching for 10 minutes towards the end of the session. This makes sure that you receive appropriate amounts of nutrients that help produce energy to spend in your high intensity weight training schedule. There is believed that a connection exists between restorative yoga and obesity. Hence you need to stay toned and stretched through the week. It will help you maintain a healthier lifestyle, and spend time with family.
    ftmaxumyĿռ - ̳ - Powered by Discuz!