Help needed-Do u know what codes to write in this main class?

Discussions

EJB design: Help needed-Do u know what codes to write in this main class?

  1. 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) {
          }
        }
      }
  2. Hi,

    Add a public static void main (..)

    and
    call
    zipFolder with the parameters

    from the main

    Regards
    Shoj
  3. Can u show me in here?[ Go to top ]

    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!
  4. 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.
  5. Obviously u are not a nice guy[ Go to top ]

    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.
  6. Obviously you need redirection[ Go to top ]

    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