K
Kasper K
Hi,
Simple question. I want to zip a directory using
java.util.zip.ZipOutputStream. I use the code below. My problem is
that ZipEntry dosnt seems to like the danish chars "æ ø å". So when I
unzip my compressed directory the files containing those chars has
substituded them with something like "-(_/&%".
private void zipDir(File dir, ZipOutputStream out) throws Exception
{
int BUFFER = 2048;
byte data[] = new byte[BUFFER];
File files[] = dir.listFiles();
for (int i=0; i<files.length; i++)
{
if(files.isDirectory())
{
zipDir(files, out);
} else
{
FileInputStream fi = new FileInputStream(files);
BufferedInputStream origin = new BufferedInputStream(fi, BUFFER);
String name = files.getPath();
name = name.substring(3);
//System.out.println(name);
ZipEntry entry = new ZipEntry(name);
out.putNextEntry(entry);
int count;
while((count = origin.read(data, 0, BUFFER)) != -1)
{
out.write(data, 0, count);
}
origin.close();
out.closeEntry();
}
}
}
Kasper, Denmark
Simple question. I want to zip a directory using
java.util.zip.ZipOutputStream. I use the code below. My problem is
that ZipEntry dosnt seems to like the danish chars "æ ø å". So when I
unzip my compressed directory the files containing those chars has
substituded them with something like "-(_/&%".
private void zipDir(File dir, ZipOutputStream out) throws Exception
{
int BUFFER = 2048;
byte data[] = new byte[BUFFER];
File files[] = dir.listFiles();
for (int i=0; i<files.length; i++)
{
if(files.isDirectory())
{
zipDir(files, out);
} else
{
FileInputStream fi = new FileInputStream(files);
BufferedInputStream origin = new BufferedInputStream(fi, BUFFER);
String name = files.getPath();
name = name.substring(3);
//System.out.println(name);
ZipEntry entry = new ZipEntry(name);
out.putNextEntry(entry);
int count;
while((count = origin.read(data, 0, BUFFER)) != -1)
{
out.write(data, 0, count);
}
origin.close();
out.closeEntry();
}
}
}
Kasper, Denmark