Copy a world from the jar file

Discussion in 'Plugin Development' started by Badwolf330, Mar 1, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Badwolf330

    hey, how can i load a world that i have in the jar file?

    if a use a inputStream to get a file or location outof my jar it always returns null....

    Code:
    new File(Main.r.getResource("/maps/" + Target + "/").toString());
    
    Sorry for my bad english....
     
  2. Offline

    teej107

    @Badwolf330 Do a simple Google Search about copying files from the jar to a directory. I am positive you will find an answer to this mostly Java related question.
     
    mine-care likes this.
  3. Offline

    Badwolf330

    @teej107

    did search the whole day.... did try many things but nothing works....

    Code:
    try 
            {
               ArrayList<String> ignore = new ArrayList<String>(Arrays.asList("uid.dat", "session.dat"));
               if(!ignore.contains(source.getName())) 
               {
                   if(source.isDirectory()) 
                   {
                       if(!target.exists())
                       target.mkdirs();
                       String files[] = source.list();
                       for (String file : files) 
                       {
                           File srcFile = new File(source, file);
                           File destFile = new File(target, file);
                           copyWorld(srcFile, destFile);
                       }
                   }
                   else 
                   {
                       InputStream in = new FileInputStream(source);
                       OutputStream out = new FileOutputStream(target);
                       byte[] buffer = new byte[1024];
                       int length;
                       while ((length = in.read(buffer)) > 0)
                           out.write(buffer, 0, length);
                       in.close();
                       out.close();
                   }
               }
           }
            catch (IOException e) 
            {
                System.err.println(e.getMessage());
           }
    
    this works if a send a folder that isn't in the jar... but if a foldor is in the jar i can't use this... i really got no idea how to fix this...

    HELP
     
  4. Offline

    Lightspeed

    Ignore my fail I got a valid awnser below.

    Code:
    getClass().getResource("Path here")
    This code returns a file . . . of course replace it with the path of the world inside your jar.
    I hope this helps.
    It works fine for me.

    IF this doesn't help im sorry Im tired and wasn't thinking before posting. Very sorry I'll try to find an awnser(That I've loaded a file with).


    VERY SORRY

    I found this for now. Magical Clickable Blue Text To An Awnser Maybe.
     
    Last edited: Mar 3, 2016
Thread Status:
Not open for further replies.

Share This Page