function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Unzip a file - any new?



I saw several posts asking the same question. Is there a way to unzip a file in Apex in the latest release?


I could see that the best solution would be to use an external app, but I think this could be a risk for several reasons. I was also thinking about a JavaScript solution, but I'm not sure if this will work.


I would really appreciate any idea that I could follow to finish the process and make our customer happy.






Well I did some searching before replying to your post, I didn't come across any function or class in Apex which does that, but perhaps you can unzip a file using JavaScript in case you want to include this functionality on a Visual Force page, one can call the Shell command equivalent in JavaScript and you can run the exe of WinZip and the file you want to unzip as parameter to the winzip.exe.


But then I realized JavaScript has no file access whatsoever unless you run it via a standalone program such as Adobe Integrated Runtime rather than using a web browser. AIR provides add-ons to JavaScript which provide it with additional features such as file access which are not available from web pages.

So you know you can do it the round way upload the zipped file as a Static resource and then access its components , the Apex way, if all you want to do is get the file contents in the zipped file.


Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 




Thanks for your reply. It's very useful to know that JS would not work. It helps me to not to spend more time doing some researching about this.


Actually we don't mind using a VF page, or whaterver, and also the Static Resource was one of our first ideas, but I tried with no sucess.


What I did: Once I have the zip file as a new Static Resource, I tried to query it from the Controller, and access to its body, but I was not able to get the information fine, it was compressed, so not useful for us.


public String getStaticResourceFile()
    String sResourceName = 'MyZipFile';
    StaticResource myResource = [Select Id, Name, Body From StaticResource Where Name = :sResourceName];
    String myCSVFile = myResource.Body.toString();
    System.debug('myCSVFile = ' + myCSVFile);
    return myCSVFile;


Do you know any other way to do it?


Thanks for you help. Your post gave me some hope.


Hi again,


I followed researching and I found this post but when I tried I got this error message: 404 status code return from request to


Any idea?


This is my test code:


public String getCSVFile()
    String resourceName = 'myZipTest';
    String statResourceURL = getResourceURL(resourceName);
    PageReference pageRef = 
        new PageReference(statResourceURL + '/myZipTest.csv');
    // Get the content of this PageReference as a Blob
    Blob csvBlob = pageRef.getContent();
    String myfile = csvBlob.toString();
    return myfile;
public static String getResourceURL(String resourceName)
    List<StaticResource> resourceList = [SELECT 
					 FROM StaticResource
					 WHERE Name = :resourceName];

    if (resourceList.size() == 1)
        String namespace = resourceList[0].NamespacePrefix;
   	return '/resource/' + 
   		resourceList[0].SystemModStamp.getTime() + '/' + 
   		(namespace != null && namespace != '' ? namespace + '__': '') + 
        return '';





I am Nagesh. I am new dev for

I want to find, How can we read files using apex language on platform.


Is there any way to read property files???


I have tried following ways to read file but i havn't get success.

1) create simple file '' in staticResource in force IDE. and try to populate it from StaticResource Table.

2) Using file app upload a file and try to populate it from Document Table.

In both case, No rows generated.


Please help me to solve this problem.

Send mail on::


Thanks in advanced





Would you mind creating a different post with your question? I will reply you there, and in case I'm not useful, some other people will be able to give you their feedback. If you leave your post here, no one ese will find it as the topic is different from mine.


Also, could you reply to this question? Do you need to read a file or do you need to create a file on a Document or Static Resource. Is this a csv file or has any fixed structure?






Thanks for giving reply to this message.


I have created separate another post for the same.


My requirement is to read property (Key=Value pair format ) file using Apex language on


I dont know how to store file on and how to access it to read via coding.

Is apex provide any APIS to read file ???

Is there any class like java Properties class to read property files ???


E.g I have '' file having Key=Value pair data. I have to read it and store this data locally and used it at runtime.


I hope u get my problem now. Please help me ASAP.


Thanks in Advanced


Pedro I Dal ColPedro I Dal Col
The Zippex library alows you to unzip files in Apex.

For example to read the names of the files in a zip archive and their content you can use this code:
Attachment sampleAttachment = [SELECT Name, Body FROM Attachment WHERE Id='<ID_OF_ATTACHMENT>'];

Zippex sampleZip = new Zippex(sampleAttachment.Body);

//Loop through all files in zip
for (String fileName : sampleZip.getFileNames())
    System.debug('file name: ' + fileName);
    System.debug('file content: ' + sampleZip.getFile(fileName).toString());