Meine Kompressionsklasse falsch funktioniert. Wenn ich versuche, einfache Datei zu komprimieren, die den Satz "etwas" enthält, gibt komprimiert und unkomprimiert etwas anderes zurück. Hier ist mein Abblasen Code:Meine deflater Klasse arbeitet incorecctly
public static void inflate(String arg) throws Exception {
try {
FileInputStream fin = new FileInputStream(arg);
InflaterInputStream in = new InflaterInputStream(fin);
FileOutputStream fout = new FileOutputStream("def.txt");
int i;
while ((i = in.read()) != -1) {
fout.write((byte) i);
fout.flush();
}
fin.close();
fout.close();
in.close();
} catch (Exception e) {
System.out.println(e);
}
new File(arg).delete();
new File("def.txt").renameTo(new File(arg));
}
public static void deflate(String arg) throws Exception {
try {
FileInputStream fin = new FileInputStream(arg);
FileOutputStream fout = new FileOutputStream("def.txt");
DeflaterOutputStream out = new DeflaterOutputStream(fout);
int i;
while ((i = fin.read()) != -1) {
out.write((byte) i);
out.flush();
}
fin.close();
out.close();
} catch (Exception e) {
System.out.println(e);
}
new File(arg).delete();
new File("def.txt").renameTo(new File(arg));
}
Ich nenne es mit
public static void main(String[] args) {
try {
Main.deflate(args[0]);
Main.inflate(args[0]);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
So wie mein Code zu beheben? Ich denke, dieses Problem besteht nicht darin, den Code zu deflationieren.
Ich habe es versucht, zu kommentieren, aber es gibt mir leere Datei. –
Ok ich habe Code umgeschrieben und es funktioniert gut. –