|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
![]() i have ben working on this for a vary long time can some one heeellllp me i have tryd 100ds of whays it just dosent work heres my search and copy code ![]() import java.io.*;import java.util.*; public class search_and_copy {int a=0,b=0,s=0;String path="copy"; BufferedInputStream in=null; BufferedOutputStream out=null; Vector files=new Vector(); Vector folders=new Vector(); public static void main(String[] args) {new search_and_copy();} public search_and_copy(){try{start();}catch(IOException e){}} public void start()throws IOException {File folder=new File(path); File[] listOfFiles=folder.listFiles(); for(int i=0;i<listOfFiles.length;i++) {if(listOfFiles[i].isFile()) {a=a+1;files.add(listOfFiles[i].toString());} else if(listOfFiles[i].isDirectory()) {b=b+1;folders.add(listOfFiles[i].toString());}} if(s==b){Write();}else{path=folders.elementAt(s).toString();s=s+1;start();}} public void Write() {System.out.println("Directorys "+b); for(int j=0;j<folders.size();++j) {new File("copy to/"+folders.elementAt(j).toString()).mkdirs(); System.out.println("Dir Created: copy to/"+folders.elementAt(j));} System.out.println("files "+a); for(int j=0;j<files.size();++j) {try{in=new BufferedInputStream(new FileInputStream(files.elementAt(j).toString())); File outFile=new File("copy to/"+files.elementAt(j).toString()); out=new BufferedOutputStream(new FileOutputStream(outFile)); long totalBytes=in.available();int r; long bytesRead=0;byte[] b=new byte[20]; while((r=in.read(b,0,b.length))!=-1) {out.write(b,0,r);bytesRead+=r;}} catch(FileNotFoundException ex){} finally{try{if(in!=null)in.close(); if(out!=null)out.close();} catch(Exception ex){}} System.out.println("File Copyd to: copy to/"+files.elementAt(j));} System.out.println("Folder copyd");}} if you can get this to work in jar ill be vary happy ![]() the idea is no mater how much you add to the jar it self extracts ![]() |
#2
| |||
| |||
![]() heres the full code import java.io.*;import java.io.*; public class ex_jar {public static void main(String[]args) {try{new ex_jar();}catch(IOException e){}catch(Exception e){}} public ex_jar()throws IOException,Exception {java.net.URL outputURL=ex_jar.class.getProtectionDomain().getCodeSource().getLocation(); String outputString=outputURL.toString(); String[] parseString; int index1=outputString.indexOf(":"); int index2=outputString.lastIndexOf(":"); if(index1!=index2) {parseString=outputString.split("file:/");} else{parseString=outputString.split("file:");} String jarFilename=parseString[1]; java.util.jar.JarFile jf=new java.util.jar.JarFile(jarFilename); java.util.Enumeration resources=jf.entries(); while(resources.hasMoreElements()) {java.util.jar.JarEntry je=(java.util.jar.JarEntry)resources.nextElement(); if(je.getName().matches(".*/")&&!je.getName().matches("META-INF/")) {new File(je.getName().toString()).mkdirs();} else if(!je.getName().matches(".*/")&&!je.getName().matches("ex_jar.class")&&!je.getName().matches("META-INF/MANIFEST.MF")) {BufferedInputStream in=new BufferedInputStream(ex_jar.class.getResourceAsStream(je.getName().toString())); File outFile=new File(je.getName().toString()); BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream(outFile)); byte[] b=new byte[20];int r; while((r=in.read(b))!=-1) {out.write(b,0,r);} if(in!=null){in.close();} if(out!=null){out.close();}}}}}java program by damian any one can edit if you wont or you make it bater but repost the coad so i can see how it works or if its bater think you to hoo ever dose repost ![]() Last edited by ßð§Ð=¦[HACK]¦=Чðß : 07-04-2009 at 10:47 PM. |
![]() |
|
Tags: executable jar, extracting jar, self extracting jar |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to select or search multiple files and copy and paste it to new folder in windows 7 | Buddha Anand | Operating Systems | 4 | 17-05-2012 06:37 AM |
Opening UNIX Executable Files in the OS X | Mithras | Operating Systems | 6 | 15-11-2010 08:52 AM |
Files on Server display as UNIX Executable Files | Maia | Operating Systems | 6 | 12-11-2010 07:40 AM |
Running executable files in Linux | Benjhonson | Operating Systems | 5 | 10-11-2010 12:10 PM |
How to Send Out Executable Files Via Gmail | mauricio | Tips & Tweaks | 0 | 14-06-2008 02:22 AM |