How to export all files and folders in resources folder in java -
this found org.bukkit.plugin.java.javaplugin , seems work
public void saveresource(string resourcepath, boolean replace) { if (resourcepath == null || resourcepath.equals("")) { throw new illegalargumentexception("resourcepath cannot null or empty"); } resourcepath = resourcepath.replace('\\', '/'); inputstream in = getresource(resourcepath); if (in == null) { throw new illegalargumentexception("the embedded resource '" + resourcepath + "' cannot found"); } file outfile = new file(datafolder, resourcepath); int lastindex = resourcepath.lastindexof('/'); file outdir = new file(datafolder, resourcepath.substring(0, lastindex >= 0 ? lastindex : 0)); if (!outdir.exists()) { outdir.mkdirs(); } try { if (!outfile.exists() || replace) { outputstream out = new fileoutputstream(outfile); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.close(); in.close(); } else { logger.log(level.warning, "could not save " + outfile.getname() + " " + outfile + " because " + outfile.getname() + " exists."); } } catch (ioexception ex) { logger.log(level.severe, "could not save " + outfile.getname() + " " + outfile, ex); } }
Comments
Post a Comment