hi, I have a problem in this set of codes,I cannot run it because I do not have a main class. Anyone have any idea what to put in the main class? Thanks!Need help urgently!
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.
*/
public static 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.
*/
private static 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.
*/
private static 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) {
}
}
}
-
Help needed-Do u know what codes to write in this main class? (5 messages)
- Posted by: apple low
- Posted on: July 10 2005 22:56 EDT
Threaded Messages (5)
- Help needed-Do u know what codes to write in this main class? by shoj rajan on July 11 2005 02:54 EDT
- Can u show me in here? by apple low on July 11 2005 11:20 EDT
- Help needed-Do u know what codes to write in this main class? by Todd Clarke on July 11 2005 23:50 EDT
- Obviously u are not a nice guy by apple low on July 13 2005 10:11 EDT
- Obviously you need redirection by Hugues Ferland on July 14 2005 12:04 EDT
- Obviously u are not a nice guy by apple low on July 13 2005 10:11 EDT
-
Help needed-Do u know what codes to write in this main class?[ Go to top ]
- Posted by: shoj rajan
- Posted on: July 11 2005 02:54 EDT
- in response to apple low
Hi,
Add a public static void main (..)
and
call
zipFolder with the parameters
from the main
Regards
Shoj -
Can u show me in here?[ Go to top ]
- Posted by: apple low
- Posted on: July 11 2005 11:20 EDT
- in response to shoj rajan
hi, very thanks for ur help but can u show the codes here,cos i don't quite know how to call the zipfolders parameters.Thanks! -
Help needed-Do u know what codes to write in this main class?[ Go to top ]
- Posted by: Todd Clarke
- Posted on: July 11 2005 23:50 EDT
- in response to apple low
Apple low,
Obviously you do not know java to any degree whatsoever. But being a nice guy and all, I will help you out. As stated by Shoj, you need to write a main method for your class. If you don't know how to do this, go read this page http://java.sun.com/docs/books/tutorial/getStarted/application/main.html
If you don't know how to call a method with parameters, you should look at the following:
http://java.about.com/library/weekly/aa_methods1.htm
Working things out yourself is lot more beneficial and rewarding than milking off the knowledge of others. Most people are willing to help provided that you have actually tried yourself and not milked a forum for several weeks.
You'll thank me one day
Todd. -
Obviously u are not a nice guy[ Go to top ]
- Posted by: apple low
- Posted on: July 13 2005 10:11 EDT
- in response to Todd Clarke
Todd,
if u are a nice guy, u would'nt speak in this kind of manner.Therefore,I will not thank u. Besides that, I am a new learner to java and since everyone here is learning about java,I think all of us should care, share and help one another. -
Obviously you need redirection[ Go to top ]
- Posted by: Hugues Ferland
- Posted on: July 14 2005 12:04 EDT
- in response to apple low
Hi apple low,
I'm reading your post since june, and now I must tell you that you are definitly not posting your question in the right forum.
Of course everyone here is learning here, but on more advance topics. This forum is about EJB design, not for beginners!
Java is a OO language and need some time to learn the basics (as most programming language). If you have not done it yet, I suggest that you buy a book, to learn the very basic of programming, and Java. This will save you headaches. You can go on any online bookstore and make a search for a good introduction book on programming and java, there is tons. Again, don't look at book about specific advance topics; You really need to start at the bottom. You'll see this will save you countless of hours (and probably to others as well).
Then, once you have read one or two books on programming with Java, and if there is something that's still obscur, find a forum for beginners Java programmer - maybe the author of the book you'll buy will suggest one... - and post your questions there. It is important that you choose the forum carefully, it is part of basic net-etiquette (see: http://www.albion.com/netiquette/corerules.html).
I hope you will not give up, but continue to persevere in your quest to lear Java and create an application of your own... But do the right things: learn.
In the name of everyone that are reading your post, I wish you the best luck!
Hugues Ferland