aspose file tools*
The moose likes I/O and Streams and the fly likes FileNotFoundException: character encoding issue zipping files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "FileNotFoundException: character encoding issue zipping files" Watch "FileNotFoundException: character encoding issue zipping files" New topic
Author

FileNotFoundException: character encoding issue zipping files

Marco Canavese
Greenhorn

Joined: Nov 12, 2013
Posts: 8
    
    1

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

Joined: Aug 07, 2007
Posts: 2317
    
  49
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

Joined: Oct 13, 2005
Posts: 39427
    
  28
Too difficult for “beginning”: moving discussion.
Marco Canavese
Greenhorn

Joined: Nov 12, 2013
Posts: 8
    
    1

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

Joined: Aug 07, 2007
Posts: 2317
    
  49
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

Joined: Nov 12, 2013
Posts: 8
    
    1

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

Joined: Aug 07, 2007
Posts: 2317
    
  49
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

Joined: Nov 12, 2013
Posts: 8
    
    1

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]

Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2317
    
  49
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FileNotFoundException: character encoding issue zipping files