1.15.2 how to copy the internal jar file outside

Discussion in 'Spigot Plugin Development' started by catssss, Apr 19, 2020.

  1. how would I copy a file from internal to the outside
     
  2. What do you mean with "internal" and "outside"? Which JAR file?
     
  3. Can you elaborate on what you mean exactly?
    A .jar file can be seen as a folder (don‘t know if it‘s compressed or not; if it is, you need an input-stream that de-compresses the file)
     
  4. They are built on the ZIP format so they are compressed.
     
    • Informative Informative x 1
  5. to read things on the inside of the jar file you need a stream or reader or whatever but how do I then take that and put it in the data folder sorry for the late reply
     
  6. I have this
    File CFile = Files.copy(in, this.getDataFolder(), CopyOption.COPY_ATTRIBUTES);
    but the copy option doesn't have .something it only is copy option but the standardcopyoption does but when I try and use that it says that copy() is not applicable for the arguments standardcopyoption should I just cast it?

    edit: I figured out my problem I now have Files.copy(getClass().getResourceAsStream("config.yml"), this.getDataFolder().toPath(), StandardCopyOption.REPLACE_EXISTING); but it still isn't working (I create the file to replace before it)
     
    #8 catssss, Apr 19, 2020
    Last edited: Apr 19, 2020
  7. Just use JavaPlugin#saveResource(String, boolean)...
     
  8. You have to use ClassLoader#getResourceAsStream(String). But consider using this: