`
收藏列表
标题 标签 来源
文件压缩 java 果断删除没用的代码
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.tools.zip.ZipOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Enumeration;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile;

/**
 * YouAreStupid
 * 集合网上几个比较好的例子,使用org.apache.tools.zip包下的类解决zip压缩中的
 * 中文文件名问题
 */
public class ZipUtil {

    public static boolean doZip(String filesDirPath, String zipFilePath) {
        return doZip(new File(filesDirPath), zipFilePath);
    }

    private static boolean doZip(File inputFile, String zipFileName) {
        ZipOutputStream out = null;
        try {
            out = new ZipOutputStream(new FileOutputStream(zipFileName));
            boolean result = doZip(out, inputFile, "");

            return result;
        } catch (FileNotFoundException ex) {
            //ex.printStackTrace();
            return false;
        } catch (IOException ex) {
            //ex.printStackTrace();
            return false;
        } finally {
            try {
                out.close();
            } catch (IOException ex) {
                //ex.printStackTrace();
                return false;
            }
        }
    }

    private static boolean doZip(ZipOutputStream out, File f, String base) {
        try {
            if (f.isDirectory()) {
                File[] fl = f.listFiles();
                out.putNextEntry(new org.apache.tools.zip.ZipEntry(base + "/"));
                base = base.length() == 0 ? "" : base + "/";
                for (int i = 0; i < fl.length; i++) {
                    doZip(out, fl[i], base + fl[i].getName());
                }
            } else {
                out.putNextEntry(new org.apache.tools.zip.ZipEntry(base));
                FileInputStream in = new FileInputStream(f);
                int b;
                while ((b = in.read()) != -1) {
                    out.write(b);
                }
                in.close();
            }
            return true;
        } catch (IOException ex) {
            //ex.printStackTrace();
            return false;
        }
    }

    public static boolean unZip(String srcFile, String dest, boolean deleteFile) {
        try {
            File file = new File(srcFile);
            if (!file.exists()) {
                //throw new RuntimeException("解压文件不存在!");
                return false;
            }
            ZipFile zipFile = new ZipFile(file);
            Enumeration e = zipFile.getEntries();
            while (e.hasMoreElements()) {
                ZipEntry zipEntry = (ZipEntry) e.nextElement();
                if (zipEntry.isDirectory()) {
                    String name = zipEntry.getName();
                    name = name.substring(0, name.length() - 1);
                    File f = new File(dest + name);
                    f.mkdirs();
                } else {
                    File f = new File(dest + zipEntry.getName());
                    f.getParentFile().mkdirs();
                    f.createNewFile();
                    InputStream is = zipFile.getInputStream(zipEntry);
                    FileOutputStream fos = new FileOutputStream(f);
                    int length = 0;
                    byte[] b = new byte[1024];
                    while ((length = is.read(b, 0, 1024)) != -1) {
                        fos.write(b, 0, length);
                    }
                    is.close();
                    fos.close();
                }
            }

            if (zipFile != null) {
                zipFile.close();
            }

            if (deleteFile) {
                file.deleteOnExit();
            }

            return true;
        } catch (IOException ex) {
            return false;
        }
    }

    public static void main(String[] args) throws Exception {
        //压缩文件夹
        boolean resultOfZip = ZipUtil.doZip("E:/ZipTest/MyFiles", "E:/ZipTest/test.youarestupid");

        //解压缩
        boolean resultOfUnZip = ZipUtil.unZip("E:/ZipTest/test.youarestupid", "E:/ZipTest/youarestupid/", false);

        System.out.println("压缩结果:" + resultOfZip + "\n解压缩结果:" + resultOfUnZip);
    }
}
dblink
create database link dblink   connect to system identified by "987654321"   using'(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = xe)))';
ff
drop database link source_link;
create database link source_link
   connect to user identified by password
   using
'(DESCRIPTION =
  (ADDRESS_LIST =
  (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
  )
  (CONNECT_DATA =
  (SERVICE_NAME = orcl)
  )
  )'
;
MAVEN总结 maven 插件总结
<properties>
		<!-- 主要依赖库的版本定义 -->
		<jetty.version>6.1.26</jetty.version>
		<jdk.version>1.6</jdk.version>
		<!-- Plugin的属性定义 -->
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>
	
	<dependencies>
		<!-- j2ee web spec -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>2.5</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>
		<dependency>
			<groupId>taglibs</groupId>
			<artifactId>standard</artifactId>
			<version>1.1.2</version>
		</dependency>

		<!-- test begin -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.8.1</version>
			<scope>test</scope>
		</dependency>

		<!-- jetty -->
		<dependency>
			<groupId>org.mortbay.jetty</groupId>
			<artifactId>jetty</artifactId>
			<version>${jetty.version}</version>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>org.mortbay.jetty</groupId>
			<artifactId>jsp-2.1-jetty</artifactId>
			<version>${jetty.version}</version>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<!-- compiler插件, 设定JDK版本 -->
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.3.2</version>
				<configuration>
					<source>${jdk.version}</source>
					<target>${jdk.version}</target>
					<showWarnings>true</showWarnings>
				</configuration>
			</plugin>

			<!-- war插件 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.1</version>
				<configuration>
					<warName>${project.artifactId}</warName>
				</configuration>
			</plugin>

			<!-- resource插件, 设定编码 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>2.4.3</version>
				<configuration>
					<encoding>${project.build.sourceEncoding}</encoding>
				</configuration>
			</plugin>

			<!-- jar插件 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<version>2.3.1</version>
				<configuration>
					<archive>
						<manifest>
							<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
							<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
						</manifest>
					</archive>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-source-plugin</artifactId>
				<version>2.1.2</version>
			</plugin>

			<!-- eclipse插件 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-eclipse-plugin</artifactId>
				<version>2.8</version>
				<configuration>
					<wtpversion>2.0</wtpversion>
					<!-- 额外的eclipse外观 -->
					<!-- <additionalProjectFacets> </additionalProjectFacets> -->
					<!-- 不打包.svn文件 -->
					<sourceExcludes>
						<sourceExclude>**/.svn/</sourceExclude>
					</sourceExcludes>
					<downloadSources>true</downloadSources>
					<!-- <downloadJavadocs>true</downloadJavadocs> -->
				</configuration>
			</plugin>

			<!-- jetty插件 -->
			<plugin>
				<groupId>org.mortbay.jetty</groupId>
				<artifactId>maven-jetty-plugin</artifactId>
				<version>${jetty.version}</version>
				<configuration>
					<!-- 项目直接放在根目录下运行 -->
					<contextPath>/</contextPath>
					<connectors>
						<!-- 使用NIO提升性能 -->
						<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
							<!-- 配置监听端口 -->
							<port>8080</port>
						</connector>
					</connectors>
					<reload>manual</reload>
				</configuration>
			</plugin>
		</plugins>
	</build>
Global site tag (gtag.js) - Google Analytics