So I want to have a world and later multiple worlds that will get deleted and then copied again from the default worldfile. I didn't write the deleting yet because if I got this fixed, then I probably won't be having problems with deleting it. Code:java import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.i:confused:utputStream;import java.util.logging.Logger; import org.bukkit.entity.Player; public class CopyWorld { public static Main plugin; public CopyWorld(Main instance) {plugin = instance;} private static Logger log = plugin.log; public static void main(Player player){String name = player.getName();File srcFolder = new File(plugin.getConfig().getString("Config.CopyFromWorld"));File destFolder = new File(plugin.getConfig().getString("Config.CopyToWorld")); //make sure source existsif(!srcFolder.exists()){ plugin.MessageConvert(player, "Messages.Start/Stop.CopyFromWorld_DoesNotExist");plugin.ServerMessageConvert(name, "Messages.Start/Stop.CopyFromWorld_DoesNotExist"); }else{ try{copyFolder(srcFolder,destFolder);}catch(IOException e){e.printStackTrace();plugin.MessageConvert(player, "Messages.Start/Stop.Error");plugin.ServerMessageConvert(name, "Messages.Start/Stop.Error");}} log.info("Done");} public static void copyFolder(File src, File dest)throws IOException{ if(src.isDirectory()){ // If directory not exists, create itif(!dest.exists()){dest.mkdir();log.info("Directory copied from "+ src + " to " + dest);} // List all the directory contentsString files[] = src.list(); for (String file : files) {// Construct the src and dest file structureFile srcFile = new File(src, file);File destFile = new File(dest, file);// Recursive copycopyFolder(srcFile,destFile);} }else{// If file, then copy it// Use bytes stream to support all file typesInputStream in = new FileInputStream(src);OutputStream out = new FileOutputStream(dest); byte[] buffer = new byte[1024]; int length;// Copy the file content in byteswhile ((length = in.read(buffer)) > 0){out.write(buffer, 0, length);} in.close();out.close();log.info("File copied from " + src + " to " + dest);}}} Messageconvert gets the path from config and does some stuff with it like colors and sends it to the player. Servermessageconvert does the same but sends it to the console. But what's wrong here? And these are the worlds: Code:java config.addDefault("Config.CopyFromWorld", "/world_gamedefault"); config.addDefault("Config.CopyToWorld", "/world_game");
if(!dest.exists()){ dest.mkdir(); and then you're calling mkdir for all files and folders, so it may create dirs, but never copy files (as either dest doesn't exist or it is a dir from a previous run).
// If file, then copy it // Use bytes stream to support all file types Nvm, the problem is the location of the worldfolders, what's wrong with that? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Do I have to start from the C drive or is there a way that I can use the location where the Craftbukkit jar is?
Code: String path = new File(".").getAbsolutePath(); That will give you the current path which should be the path to the folder where craftbukkit/server is in.