Results 1 to 2 of 2

Thread: Search inside executable jar copy files out ResourceAsStream

  1. #1

    idea Search inside executable jar copy files out ResourceAsStream

    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. #2

    star Re: search inside executable jar copy files out ResourceAsStream

    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.

Similar Threads

  1. Replies: 4
    Last Post: 17-05-2012, 06:37 AM
  2. Opening UNIX Executable Files in the OS X
    By Mithras in forum Operating Systems
    Replies: 6
    Last Post: 15-11-2010, 08:52 AM
  3. Files on Server display as UNIX Executable Files
    By Maia in forum Operating Systems
    Replies: 6
    Last Post: 12-11-2010, 07:40 AM
  4. Running executable files in Linux
    By Benjhonson in forum Operating Systems
    Replies: 5
    Last Post: 10-11-2010, 12:10 PM
  5. How to Send Out Executable Files Via Gmail
    By mauricio in forum Tips & Tweaks
    Replies: 0
    Last Post: 14-06-2008, 02:22 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,039,388.03272 seconds with 16 queries