Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.File;

public class Main {
    /** 
     *create the zip file path
     */
    private static String buildDestinationZipFilePath(File srcFile, String destParam) {
        createDestDirectoryIfNecessary(destParam);

        String fileName = "";
        if (srcFile.isDirectory()) {
            fileName = srcFile.getName();
        } else {
            fileName = srcFile.getName().substring(0, srcFile.getName().lastIndexOf("."));
        }

        if (destParam.endsWith(File.separator)) {
            destParam += fileName + ".zip";
        } else {
            destParam += File.separator + fileName + ".zip";
        }
        // }  
        return destParam;
    }

    /** 
     * Create the directory for Zip file if necessary
     */
    private static void createDestDirectoryIfNecessary(String destParam) {
        File destDir = null;
        destDir = new File(destParam);
        //        if (destParam.endsWith(File.separator)) {  
        //            destDir = new File(destParam);  
        //        } else {  
        //            destDir = new File(destParam.substring(0, destParam.lastIndexOf(File.separator)));  
        //        }  
        if (!destDir.exists()) {
            destDir.mkdirs();
        }
    }
}