File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileNotFoundException: character encoding issue zipping files

 
Marco Canavese
Greenhorn
Posts: 17
1
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
first of all as a new member let me briefly introduce myself: I'm studying Java since a few months now and I'm really a beginner. I'm using prof. Horstmann books as reference guides (mainly Java concepts and Core Java vol.1).
So, as a new member guess what? Question time...

Goal: zip files accordingly a (comma) delimited input
Working input sample:


Issue: Program posted below works fine when to be zipped file names don't contain any "special" character which is part of a foreign alphabet (i.e. ü, á, é, ö for Hungarian, ž, č for Slovenian, etc), as for example in working sample Input above. When I have special characters in filenames I get a FileNotFoundException error when creating a new ZipOutputStream Object

Not working input sample:


Could you point me in the right direction in order to address this situation?
Of course suggestions to edit (because something is wrong) or to improve code are also welcomed, as I stated I'm in the early stages of the learning curve.

Thanks a lot!

Ziputil.java


TestZipUtil.java
 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Sorry, but I'm not clear as to your exact problem. You say you get a "FileNotFoundException error when creating a new ZipOutputStream Object" but the file names you have shown containing special characters are the input files names ie the ZipEntry names. Do you mean you get a problem when calling addFileToZip()?

Please post the full error message and stack trace so we can see exactly what and where the problem is.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too difficult for “beginning”: moving discussion.
 
Marco Canavese
Greenhorn
Posts: 17
1
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it!
Thanks Tony for pointing me in the right direction!
Indeed it was strange the exception was thrown when creating the ZipOutputStream object (destZipFile), and even stranger it was the exception was not thrown with the first set of input.
This gave me a clue about looking at the input file rather than character encoding.
In fact it appeared that the input file type giving issues had been saved as UTF-8 with Byte Order Mark. I then re-saved it as UTF-8 only and it works as expected.
One minor issue which anyway I can stand for is that filenames containing "special" characters are not displayed correctly inside the archive, but when I extract them everything is ok:
CIB-EQ$0000060 Tervezés és Kontrolling-BUMed1.pdf

CIB-EQ$0000070 Csoportszintű Pénzügyi Beszámolók-BUMed1.pdf

Edit: character map set used by this web application is also different from mine, anyway it was just to point out the fact.
Cheers,
Marco
 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad to hear you've solved your problem.

One minor issue which anyway I can stand for is that filenames containing "special" characters are not displayed correctly inside the archive

Not displayed correctly by what?
 
Marco Canavese
Greenhorn
Posts: 17
1
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, sorry. Opening the archive with my italian Windows 7 system and the built-in zipper utility, characters are shown as posted above. But it makes sense.
What matters is that it works fine with other applications (i.e. WinRAR, 7-ZIP).
Once again thanks,
Marco
 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect that a function of the viewer or more precisely the font used by the viewer. Try using the built in zip utility to manually zip up files with special characters in the name and see if how they display when viewed.
 
Marco Canavese
Greenhorn
Posts: 17
1
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It even doesn't allow to zip them. See attached pic.
Quick translation of the text from italian: it's not possible to zip...There are characters which can't be utilized within a compressed folder. It's advisable to renamerename the file or the directory.
Nevermind, this is not an issue at all for me.
Marco
W7_BuiltIn_Zip.PNG
[Thumbnail for W7_BuiltIn_Zip.PNG]
 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know I shouldn't be surprised that Win 7's built in zip utility doesn't handle international characters in file names but I am.
Maybe a should just be impressed that it handles longer files names than 8.3 format
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic