• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with chinese fileNames in a Zipfile  RSS feed

 
sreenath reddy
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I have a really strange problem . I needed to create a zip file(English name) and add a chinese file to that Zip . I had done this using java.uti.zip and in the output zip file i am seeing a totally different chiense name than what i had expected . My code looks like this

String fileName = "用户名";(Chinese fileName)
File zipFile = new File("abc.txt");
ZipOutputStream zipOutStrm = null;
BufferedInputStream in = null;
try
{
int length = 0;
byte[] buffer = new byte[2048];

zipOutStrm = new ZipOutputStream(new FileOutputStream("abc.zip"));
ZipEntry zipe = new ZipEntry(fileName);
zipOutStrm.putNextEntry(zipe);
in = new BufferedInputStream(new FileInputStream(zipFile));
length = in.read(buffer);
while(length != -1)
{
zipOutStrm.write(buffer, 0, length);
length = in.read(buffer);

}
}
catch(FileNotFoundException e)
{

e.printStackTrace();
}
catch(IOException e)
{

e.printStackTrace();
}
finally
{
try
{
in.close();
zipOutStrm.closeEntry();
zipOutStrm.close();
}
catch(Exception e)
{
//do nothing ;
}
}

Later i found out from the sun site that there is some encoding issues with the way java does the zip and winZip encoding .

Can any one let me know how to come out of this ??
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!