Hallo ihr,
ich habe ein kleines Problem, ich habe für meine Mod jetzt einen Installer geschrieben, da mich mehrere drum gebeten haben, alles funktioniert einwandfrei, nur wenn ich versuche die Datei in einen Ordner zu kopieren kriege ich folgende Meldung:
Bei folgendem Code:
Main.java
CopyFile.java
Und mein Debugmode sagt:
Alles bezieht sich auf:
In diesen Ordner soll die minecraft.jar reinkopiert werden.
Wie kann ich das Problem lösen? Ich habe mich schon stundenlang durchgegooglet aber nichts gefunden
MfG:
Florilu
ich habe ein kleines Problem, ich habe für meine Mod jetzt einen Installer geschrieben, da mich mehrere drum gebeten haben, alles funktioniert einwandfrei, nur wenn ich versuche die Datei in einen Ordner zu kopieren kriege ich folgende Meldung:
Code:
java.io.FileNotFoundException: C:\Users\Florian\AppData\Roaming\.minecraft\EBGBackup (Zugriff verweigert)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at CopyFile.copy(CopyFile.java:29)
at Main.main(Main.java:47)
Bei folgendem Code:
Main.java
Java:
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Scanner;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class Main
{
static String path = System.getProperty("user.home") + File.separatorChar + "AppData/";
static String mainFolder = System.getProperty("user.home") + File.separatorChar + "Appdata/Roaming/.minecraft/";
static String test = System.getProperty("user.home");
static File backup = new File(path + "Roaming/.minecraft/EBGBackup/");
static File minecraft = new File(path + "Roaming/.minecraft/bin/minecraft.jar");
static File mcOut = new File(path + "Roaming/.minecraft/EBGBackup/");
static File finalOut = new File(path + "Roaming/.minecraft/bin/minecraft.jar");
static Scanner scanner = new Scanner(System.in);
static File readme;
static FileWriter writer;
public static void main(String[] args) throws Exception {
System.out.println("EBG Installation Assistant for EBG V1.2.4 (1.4.7) by Florilu");
System.out.println("Options: ");
System.out.println("Install: [1]");
System.out.println("Refresh jar: [2]");
System.out.println("Exit: [3]");
System.out.print("Choose Optionnumber: ");
int num = scanner.nextInt();
if (num == 1) {
if(!backup.exists()){
backup.mkdir();
}
if(backup.exists()){
System.out.println(minecraft + " " + mcOut);
System.out.println("Backupping your jar!");
check();
CopyFile.copy(minecraft, mcOut);
check();
System.out.println("Backup Complete!");
}
new Main().extractArchive(new File("files/install.zip"), new File(path + "Roaming/.minecraft/bin"));
System.out.println("ExtraBiomesGen has been installed.");
}
if (num == 3) {
System.exit(0);
}
if (num == 2){
if (!minecraft.exists()) {
new Main().extractArchive(new File("files/refresh.zip"), new File(path + "Roaming/.minecraft/bin"));
System.out.println("Your jar has been refreshed!");
}else{
minecraft.delete();
new Main().extractArchive(new File("files/refresh.zip"), new File(path + "Roaming/.minecraft/bin"));
System.out.println("Your jar has been refreshed!");
}
}
}
public static void check(){
System.out.println("CanRead:" + mcOut.canRead());
System.out.println("CanWrite" + mcOut.canWrite());
System.out.println("Exists:" + mcOut.exists());
System.out.println("AbsolutePath:" + mcOut.getAbsolutePath());
System.out.println("IsDirectory:" + mcOut.isDirectory());
}
public static void write() throws IOException{
String text = "The Backupfunction is still WIP, be sure you'll backup your jar by yourself!";
String dateiName = mainFolder + "EBGBackup/README.txt";
FileOutputStream schreibeStrom = new FileOutputStream(dateiName);
for (int i=0; i < text.length(); i++){
schreibeStrom.write((byte)text.charAt(i));
}
schreibeStrom.close();
}
public void extractArchive(File archive, File destDir) throws Exception {
if (!destDir.exists()) {
destDir.mkdir();
}
minecraft.delete();
write();
ZipFile zipFile = new ZipFile(archive);
Enumeration entries = zipFile.entries();
byte[] buffer = new byte[16384];
int len;
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
String entryFileName = entry.getName();
if (entry.isDirectory()) {
File dir = new File(destDir, entryFileName);
// System.out.println(dir);
if (!dir.exists()) {
dir.mkdir();
}
} else {
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(new File(destDir, entryFileName)));
BufferedInputStream bis = new BufferedInputStream(zipFile
.getInputStream(entry));
while ((len = bis.read(buffer)) > 0) {
bos.write(buffer, 0, len);
}
bos.flush();
bos.close();
bis.close();
}
}
}
}
CopyFile.java
Java:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.ByteChannel;
import java.nio.channels.FileChannel;
public class CopyFile {
static long chunckSizeInBytes;
boolean verbose;
public CopyFile(){
this.chunckSizeInBytes = 1024 * 1024; //Standard: Buffer 1MB
this.verbose = false; //Statistics about Copy Process
}
public CopyFile(boolean verbose){
this.chunckSizeInBytes = 1024 * 1024; //Standard: Buffer 1MB
this.verbose = verbose; //Statistics about Copy Process
}
public CopyFile(long chunckSizeInBytes){
this.chunckSizeInBytes = chunckSizeInBytes; //Custom Buffer (Bytes)
this.verbose = false; //Statistics about Copy Process
}
public CopyFile(long chunckSizeInBytes, boolean verbose){
this.chunckSizeInBytes = chunckSizeInBytes; //Custom Buffer (Bytes)
this.verbose = verbose; //Statistics about Copy Process
}
public static void copy(File source, File destination) {
try {
FileInputStream fileInputStream = new FileInputStream(source);
FileOutputStream fileOutputStream = new FileOutputStream(destination);
FileChannel inputChannel = fileInputStream.getChannel();
FileChannel outputChannel = fileOutputStream.getChannel();
transfer(inputChannel, outputChannel, source.length(), false);
fileInputStream.close();
fileOutputStream.close();
destination.setLastModified(source.lastModified());
} catch (Exception e) {
e.printStackTrace();
}
}
public static void transfer(FileChannel fileChannel, ByteChannel byteChannel, long lengthInBytes, boolean verbose)
throws IOException {
long overallBytesTransfered = 0L;
long time = -System.currentTimeMillis();
while (overallBytesTransfered < lengthInBytes) {
long bytesTransfered = 0L;
bytesTransfered = fileChannel.transferTo(overallBytesTransfered, Math.min(chunckSizeInBytes, lengthInBytes - overallBytesTransfered), byteChannel);
overallBytesTransfered += bytesTransfered;
if (verbose) {
System.out.println("overall bytes transfered: " + overallBytesTransfered + " progress " + (Math.round(overallBytesTransfered / ((double) lengthInBytes) * 100.0)) + "%");
}
}
time += System.currentTimeMillis();
if (verbose) {
System.out.println("Transfered: " + overallBytesTransfered + " bytes in: " + (time / 1000) + " s -> " + (overallBytesTransfered / 1024.0) / (time / 1000.0) + " kbytes/s");
}
}
}
Und mein Debugmode sagt:
Code:
CanRead:true
CanWritetrue
Exists:true
AbsolutePath:C:\Users\Florian\AppData\Roaming\.minecraft\EBGBackup
IsDirectory:true
Alles bezieht sich auf:
Java:
static File mcOut = new File(path + "Roaming/.minecraft/EBGBackup/");
Wie kann ich das Problem lösen? Ich habe mich schon stundenlang durchgegooglet aber nichts gefunden
MfG:
Florilu