-
source codes to zip the entire folder not just files by files (9 messages)
- Posted by: apple low
- Posted on: June 29 2005 22:26 EDT
Anyone know how to zip folder? I don't want to zip files by files? Can show it here? Thanks!Threaded Messages (9)
- Sorce Code by Mohit Gupta on July 01 2005 02:08 EDT
- Program cannot be run->think needs a main class by apple low on July 09 2005 15:37 EDT
-
Source code to call FolderZiper by Rohit Sharma on November 05 2011 03:18 EDT
- code not copied correctly by Rohit Sharma on November 05 2011 03:24 EDT
-
Source code to call FolderZiper by Rohit Sharma on November 05 2011 03:18 EDT
- Thank you for sharing by Sabre Schen on March 19 2013 23:22 EDT
- The arrangement of waiting area seating by archer archibald on April 26 2013 16:43 EDT
- There are so many different by archer archibald on April 28 2013 09:23 EDT
- Program cannot be run->think needs a main class by apple low on July 09 2005 15:37 EDT
- zipping a directory by kareem afroz on April 22 2013 03:00 EDT
- If used correctly you always have matching by baron barnaby on April 30 2013 13:09 EDT
-
Sorce Code[ Go to top ]
- Posted by: Mohit Gupta
- Posted on: July 01 2005 02:08 EDT
- in response to apple low
import java.io.File;
import java.util.zip.ZipOutputStream;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.util.zip.ZipEntry;
/**
* FolderZiper provide a static method to zip a folder.
*
* @author pitchoun
*/
public class FolderZiper {
/**
* Zip the srcFolder into the destFileZipFile. All the folder subtree of the src folder is added to the destZipFile
* archive.
*
* TODO handle the usecase of srcFolder being en file.
*
* @param srcFolder String, the path of the srcFolder
* @param destZipFile String, the path of the destination zipFile. This file will be created or erased.
*/
static public void zipFolder(String srcFolder, String destZipFile) {
ZipOutputStream zip = null;
FileOutputStream fileWriter = null;
try {
fileWriter = new FileOutputStream(destZipFile);
zip = new ZipOutputStream(fileWriter);
}
catch (Exception ex){
ex.printStackTrace();
System.exit(0);
}
addFolderToZip("", srcFolder, zip);
try {
zip.flush();
zip.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* Write the content of srcFile in a new ZipEntry, named path+srcFile, of the zip stream. The result
* is that the srcFile will be in the path folder in the generated archive.
*
* @param path String, the relatif path with the root archive.
* @param srcFile String, the absolute path of the file to add
* @param zip ZipOutputStram, the stream to use to write the given file.
*/
static private void addToZip(String path, String srcFile, ZipOutputStream zip) {
File folder = new File(srcFile);
if (folder.isDirectory()) {
addFolderToZip(path, srcFile, zip);
}
else {
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
try {
FileInputStream in = new FileInputStream(srcFile);
zip.putNextEntry(new ZipEntry(path +"/"+ folder.getName()));
while ((len = in.read(buf)) > 0) {
zip.write(buf, 0, len);
}
}
catch (Exception ex){
ex.printStackTrace();
}
}
}
/**
* add the srcFolder to the zip stream.
*
* @param path String, the relatif path with the root archive.
* @param srcFile String, the absolute path of the file to add
* @param zip ZipOutputStram, the stream to use to write the given file.
*/
static private void addFolderToZip(String path, String srcFolder, ZipOutputStream zip) {
File folder = new File(srcFolder);
String fileListe[] = folder.list();
try {
int i = 0;
while (true) {
addToZip(path+"/"+ folder.getName(), srcFolder+"/"+fileListe[i], zip);
i++;
}
}
catch (Exception ex) {
}
}
} -
Program cannot be run->think needs a main class[ Go to top ]
- Posted by: apple low
- Posted on: July 09 2005 15:37 EDT
- in response to Mohit Gupta
hi, a big thank u to mohit and all.......for the above codes rite, the program cannot be run cos there isn't the hyperlink "run" to run it. think it's becos there is no main class so i was wondering if there are any codes needed for the main class.Can someone help mi with this,can write down the codes here? Thanks! -
Source code to call FolderZiper[ Go to top ]
- Posted by: Rohit Sharma
- Posted on: November 05 2011 15:18 EDT
- in response to apple low
import java.io.*;
class UseFolderZiper
{
public static void main(String args[])throws IOException
{
BufferedReader cin=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter folder nameto be zipped");
String fileName=cin.readLine();
String fileNameUnixStyle=fileName.replace('
','/');
FolderZiper obj=new FolderZiper();
obj.zipFolder(fileNameUnixStyle,fileName+".zip");
}
}place FolderZiper.class path in the same folder as of UseFolderZiper.java
And then compile and execute UseFolderZiper.java
-
code not copied correctly[ Go to top ]
- Posted by: Rohit Sharma
- Posted on: November 05 2011 15:24 EDT
- in response to Rohit Sharma
Replace this statement
String fileNameUnixStyle=fileName.replace('
','/');with
String fileNameUnixStyle=fileName.replace('two backward slashes','/');
manually enter 2 backward slashes \ .These were removed while converting to HTML page.
-
Thank you for sharing[ Go to top ]
- Posted by: Sabre Schen
- Posted on: March 19 2013 23:22 EDT
- in response to Mohit Gupta
Thank you for sharing your ideas here. The information is really useful for me. - Michael Courouleau
-
The arrangement of waiting area seating[ Go to top ]
- Posted by: archer archibald
- Posted on: April 26 2013 16:43 EDT
- in response to Mohit Gupta
The arrangement of waiting area seating becomes an issue when the business has a large number of customers that need to have a place to sit and need to stay in those seats for long periods of time.professional essay writers -
There are so many different[ Go to top ]
- Posted by: archer archibald
- Posted on: April 28 2013 21:23 EDT
- in response to archer archibald
There are so many different benefits to online college courses, it doesn't make sense not to go back to school. With a degree, you can open the door to multiple different job opportunities for yourself, even in this economy. personal statement essay -
zipping a directory[ Go to top ]
- Posted by: kareem afroz
- Posted on: April 22 2013 03:00 EDT
- in response to apple low
Hi..in the code it shows to zip a single folder..but if we want to zip a entire directory which contains many sub folders and sub folders then????i have the code for it in java..but i want in android ....can any one help me??? -
If used correctly you always have matching[ Go to top ]
- Posted by: baron barnaby
- Posted on: April 30 2013 13:09 EDT
- in response to apple low
If used correctly you always have matching labelled information tickled in an indexed folder to you as you arrive at that very same day. It is a sequenced delivery system for paper based information custom essay writing service