2013-06-02 03:43:56 +02:00
|
|
|
package StevenDimDoors.mod_pocketDim.helpers;
|
|
|
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
|
|
|
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
|
|
|
|
|
|
|
public class copyfile
|
|
|
|
{
|
|
|
|
public static boolean copyFile(String ori, String dest)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-06-20 10:47:16 +02:00
|
|
|
//Note: For this to work properly, you must use getClass() on an instance of the class,
|
|
|
|
//not on the value obtained from .class. That was what caused this code to fail before.
|
|
|
|
//SchematicLoader didn't have this problem because we used instances of it.
|
|
|
|
InputStream in = mod_pocketDim.instance.getClass().getResourceAsStream(ori);
|
2013-06-16 16:54:03 +02:00
|
|
|
OutputStream out = new FileOutputStream(dest);
|
|
|
|
byte[] buf = new byte[1024];
|
|
|
|
int len;
|
|
|
|
while ((len = in.read(buf)) > 0) {
|
|
|
|
out.write(buf, 0, len);
|
|
|
|
}
|
|
|
|
in.close();
|
|
|
|
out.close();
|
2013-06-02 03:43:56 +02:00
|
|
|
}
|
2013-06-20 10:47:16 +02:00
|
|
|
catch (Exception e)
|
2013-06-02 03:43:56 +02:00
|
|
|
{
|
2013-06-20 10:47:16 +02:00
|
|
|
System.out.println("Unable to get resource: " + ori);
|
2013-06-02 03:43:56 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|