BufferedReader fr = new BufferedReader(new FileReader(fileChooser.getSelectedFile())); BufferedWriter fw = new BufferedWriter(new FileWriter(deviceFile)); int c; while ((c = fr.read()) != -1) { fw.write(c); } fr.close(); fw.close();
FileInputStream fis  = new FileInputStream(fileChooser.getSelectedFile()); FileOutputStream fos = new FileOutputStream(deviceFile); byte[] buf = new byte[1024]; int i = 0; while((i=fis.read(buf))!=-1) { fos.write(buf, 0, i); } fis.close(); fos.close();
    public void actionPerformed(ActionEvent ev)    {      if (fileChooser == null) {        fileChooser = new JFileChooser();        fileChooser.setFileFilter(jarFileFilter);      }            ProgressJarClassLoader loader = new ProgressJarClassLoader();            if (fileChooser.showOpenDialog(instance) == JFileChooser.APPROVE_OPTION) {        String deviceClassName = null;        String deviceName = null;        try {          JarFile jar = new JarFile(fileChooser.getSelectedFile());          Manifest manifest = jar.getManifest();                    Attributes attrs = manifest.getMainAttributes();                    deviceName = attrs.getValue("Device-Name");          if (deviceName == null) {            JOptionPane.showMessageDialog(instance,                 "Missing Device-Name entry in jar manifest.",                "Error", JOptionPane.ERROR_MESSAGE);            return;          }                    deviceClassName = attrs.getValue("Device-Class");          if (deviceClassName == null) {            JOptionPane.showMessageDialog(instance,                 "Missing Device-Class entry in jar manifest.",                "Error", JOptionPane.ERROR_MESSAGE);            return;          }                    jar.close();          deviceClassName = deviceClassName.replace('.', '/');          if (deviceClassName.charAt(0) == '/') {            deviceClassName = deviceClassName.substring(1);          }          for (Enumeration e = lsDevicesModel.elements(); e.hasMoreElements(); ) {            DeviceEntry entry = (DeviceEntry) e.nextElement();            if (deviceClassName.equals(entry.getClassName())) {              JOptionPane.showMessageDialog(instance,                   "Device is already added.",                  "Info", JOptionPane.INFORMATION_MESSAGE);              return;            }          }                    loader.addRepository(fileChooser.getSelectedFile().toURL());        } catch (IOException ex) {          JOptionPane.showMessageDialog(instance,               "Error reading " + fileChooser.getSelectedFile().getName() + " file.",              "Error", JOptionPane.ERROR_MESSAGE);          return;        }                Class deviceClass = null;        try {          deviceClass = loader.findClass(deviceClassName);        } catch (ClassNotFoundException ex) {          JOptionPane.showMessageDialog(instance,               "Cannot find class defined in Device-Class entry in jar manifest.",              "Error", JOptionPane.ERROR_MESSAGE);          return;        }                  if (!J2SEDevice.class.isAssignableFrom(deviceClass)) {          JOptionPane.showMessageDialog(instance,               "Cannot find class defined in Device-Class entry in jar manifest.",              "Error", JOptionPane.ERROR_MESSAGE);          return;        }                try {          File deviceFile = File.createTempFile("dev", ".dev", Config.getConfigPath());          BufferedReader fr = new BufferedReader(new FileReader(fileChooser.getSelectedFile()));          BufferedWriter fw = new BufferedWriter(new FileWriter(deviceFile));          int c;          while ((c = fr.read()) != -1) {            fw.write(c);          }          fr.close();          fw.close();                          DeviceEntry entry =               new DeviceEntry(deviceName, deviceFile.getName(), deviceClassName, false);          lsDevicesModel.addElement(entry);          lsDevices.setSelectedValue(entry, true);        } catch (IOException ex) {          System.err.println(ex);        }      }    }    