① 下载了一个java程序,是zip包格式的,请问应该怎么运行
这是一个轻量级的Java神经网络的框架,首先你电脑上必须按照jre .
To use Neuroph in your Java appliacation add reference to neuroph-2.6.jar and all jars from lib folder from this distribution, and import required classes.
You can create and train neural networks using NeurophStudio GUI, and load them in you app, or you can create and train them directly from code using Neuroph API.
See getting started doc for more details.
把neuroph-2.6.jar 放到你的项目中,如web 项目的lib 文件夹下。就可以用了。这个不是引用程序,不能直接运行。要使用可以网络下 neuroph 去找下api
② 用JAVA ZipOutputStream做的文件压缩 压完后用PC上的解压缩软件能打开吗
测试了一下,压缩一jpg文件后用好压可以正常打开
③ java代码实现 导出zip包,无法打开zip压缩包
package com.lch.test;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class ZIP {
public static void main(String[] argv) throws Exception {
ZipFile zf = new ZipFile("E:\\wk\\LBSLEMIS201106141057\\LBSLEMIS\\test\\com\\lch\\test\\filename.zip");
for (Enumeration entries = zf.entries(); entries.hasMoreElements();) {
String zipEntryName = ((ZipEntry) entries.nextElement()).getName();
System.out.println(zipEntryName);
}
}
}
用javad 的ZipFile类的ZipEntry方法试一下 找到ZIP里面的ZipEntry方法 读取Zip里面压缩文件的内容
有可能会引用外包
你好,我不知道你说的dzp是什么格式文件,但如果是zip的压缩文件,可以看下我的这段代码
ZipFile file = new ZipFile("d:\\1.zip");
ZipEntry entry = file.getEntry("1.xml"); //假如压缩包里的文件名是1.xml
InputStream in=file.getInputStream(entry);
最后就是按照java中一贯的流的处理方式即可
可以不解压,zip包里的一个对象就是一个ZipEntry
找到你想要的那个ZipEntry,用文流写出来就可以了。追问通过ZipEntry,然后用流就可以读出里面的内容了吗?谢谢指点!
回答/**
* 解压
* @param root 输出目标
* @param zipfile zip文件
*/
protected void unzip(File root, File zipfile, String file) throws Exception {
// 解压文件不存在时返回
if (!zipfile.exists()) {
return;
}
// 释放目录不存时创建
if (!root.exists()) {
root.mkdirs();
}
// 释放目录不为目录时返回
if (!root.isDirectory()) {
return;
}
FileInputStream fin = new FileInputStream(zipfile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry entry = null;
while ((entry = zin.getNextEntry()) != null) {
// if (!entry.getName().endsWith(file)) {
// continue;
// }
File tmp = new File(root, entry.getName());
if (entry.isDirectory()) {
tmp.mkdirs();
} else {
byte[] buff = new byte[4096];
int len = 0;
tmp.getParentFile().mkdirs();
FileOutputStream fout = new FileOutputStream(tmp);
while ((len = zin.read(buff)) != -1) {
fout.write(buff, 0, len);
}
zin.closeEntry();
fout.close();
}
}
}
这里完整的解压代码。
// if (!entry.getName().endsWith(file)) {
// continue;
// }
这段打开就是只解出一个你指定的文件。
下面是测试用的。
public static void main(String[] args) throws Exception {
new CommonFiles().unzip(new File("D:\\"), new File("D:\\test.zip"),"file.txt");
}
这个例子会在D盘生成型个test文件夹,file.txt就会在里面,(里面也可能会有多个文件夹,这个取决于压缩包里文件的度)
④ 怎样用java快速实现zip文件的压缩解压缩
packagezip;
importjava.io.BufferedInputStream;
importjava.io.BufferedOutputStream;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileOutputStream;
importjava.util.Enumeration;
importjava.util.zip.CRC32;
importjava.util.zip.CheckedOutputStream;
importjava.util.zip.ZipEntry;
importjava.util.zip.ZipFile;
importjava.util.zip.ZipOutputStream;
importorg.apache.commons.lang3.StringUtils;
publicclassZipUtil{
/**
*递归压缩文件夹
*@paramsrcRootDir压缩文件夹根目录的子路径
*@paramfile当前递归压缩的文件或目录对象
*@paramzos压缩文件存储对象
*@throwsException
*/
privatestaticvoidzip(StringsrcRootDir,Filefile,ZipOutputStreamzos)throwsException
{
if(file==null)
{
return;
}
//如果是文件,则直接压缩该文件
if(file.isFile())
{
intcount,bufferLen=1024;
bytedata[]=newbyte[bufferLen];
//获取文件相对于压缩文件夹根目录的子路径
StringsubPath=file.getAbsolutePath();
intindex=subPath.indexOf(srcRootDir);
if(index!=-1)
{
subPath=subPath.substring(srcRootDir.length()+File.separator.length());
}
ZipEntryentry=newZipEntry(subPath);
zos.putNextEntry(entry);
BufferedInputStreambis=newBufferedInputStream(newFileInputStream(file));
while((count=bis.read(data,0,bufferLen))!=-1)
{
zos.write(data,0,count);
}
bis.close();
zos.closeEntry();
}
//如果是目录,则压缩整个目录
else
{
//压缩目录中的文件或子目录
File[]childFileList=file.listFiles();
for(intn=0;n<childFileList.length;n++)
{
childFileList[n].getAbsolutePath().indexOf(file.getAbsolutePath());
zip(srcRootDir,childFileList[n],zos);
}
}
}
/**
*对文件或文件目录进行压缩
*@paramsrcPath要压缩的源文件路径。如果压缩一个文件,则为该文件的全路径;如果压缩一个目录,则为该目录的顶层目录路径
*@paramzipPath压缩文件保存的路径。注意:zipPath不能是srcPath路径下的子文件夹
*@paramzipFileName压缩文件名
*@throwsException
*/
publicstaticvoidzip(StringsrcPath,StringzipPath,StringzipFileName)throwsException
{
if(StringUtils.isEmpty(srcPath)||StringUtils.isEmpty(zipPath)||StringUtils.isEmpty(zipFileName))
{
thrownewParameterException(ICommonResultCode.PARAMETER_IS_NULL);
}
CheckedOutputStreamcos=null;
ZipOutputStreamzos=null;
try
{
FilesrcFile=newFile(srcPath);
//判断压缩文件保存的路径是否为源文件路径的子文件夹,如果是,则抛出异常(防止无限递归压缩的发生)
if(srcFile.isDirectory()&&zipPath.indexOf(srcPath)!=-1)
{
thrownewParameterException(ICommonResultCode.INVALID_PARAMETER,".");
}
//判断压缩文件保存的路径是否存在,如果不存在,则创建目录
FilezipDir=newFile(zipPath);
if(!zipDir.exists()||!zipDir.isDirectory())
{
zipDir.mkdirs();
}
//创建压缩文件保存的文件对象
StringzipFilePath=zipPath+File.separator+zipFileName;
FilezipFile=newFile(zipFilePath);
if(zipFile.exists())
{
//检测文件是否允许删除,如果不允许删除,将会抛出SecurityException
=newSecurityManager();
securityManager.checkDelete(zipFilePath);
//删除已存在的目标文件
zipFile.delete();
}
cos=newCheckedOutputStream(newFileOutputStream(zipFile),newCRC32());
zos=newZipOutputStream(cos);
//如果只是压缩一个文件,则需要截取该文件的父目录
StringsrcRootDir=srcPath;
if(srcFile.isFile())
{
intindex=srcPath.lastIndexOf(File.separator);
if(index!=-1)
{
srcRootDir=srcPath.substring(0,index);
}
}
//调用递归压缩方法进行目录或文件压缩
zip(srcRootDir,srcFile,zos);
zos.flush();
}
catch(Exceptione)
{
throwe;
}
finally
{
try
{
if(zos!=null)
{
zos.close();
}
}
catch(Exceptione)
{
e.printStackTrace();
}
}
}
/**
*解压缩zip包
*@paramzipFilePathzip文件的全路径
*@paramunzipFilePath解压后的文件保存的路径
*@paramincludeZipFileName解压后的文件保存的路径是否包含压缩文件的文件名。true-包含;false-不包含
*/
@SuppressWarnings("unchecked")
publicstaticvoinzip(StringzipFilePath,StringunzipFilePath,booleanincludeZipFileName)throwsException
{
if(StringUtils.isEmpty(zipFilePath)||StringUtils.isEmpty(unzipFilePath))
{
thrownewParameterException(ICommonResultCode.PARAMETER_IS_NULL);
}
FilezipFile=newFile(zipFilePath);
//如果解压后的文件保存路径包含压缩文件的文件名,则追加该文件名到解压路径
if(includeZipFileName)
{
StringfileName=zipFile.getName();
if(StringUtils.isNotEmpty(fileName))
{
fileName=fileName.substring(0,fileName.lastIndexOf("."));
}
unzipFilePath=unzipFilePath+File.separator+fileName;
}
//创建解压缩文件保存的路径
FileunzipFileDir=newFile(unzipFilePath);
if(!unzipFileDir.exists()||!unzipFileDir.isDirectory())
{
unzipFileDir.mkdirs();
}
//开始解压
ZipEntryentry=null;
StringentryFilePath=null,entryDirPath=null;
FileentryFile=null,entryDir=null;
intindex=0,count=0,bufferSize=1024;
byte[]buffer=newbyte[bufferSize];
BufferedInputStreambis=null;
BufferedOutputStreambos=null;
ZipFilezip=newZipFile(zipFile);
Enumeration<ZipEntry>entries=(Enumeration<ZipEntry>)zip.entries();
//循环对压缩包里的每一个文件进行解压
while(entries.hasMoreElements())
{
entry=entries.nextElement();
//构建压缩包中一个文件解压后保存的文件全路径
entryFilePath=unzipFilePath+File.separator+entry.getName();
//构建解压后保存的文件夹路径
index=entryFilePath.lastIndexOf(File.separator);
if(index!=-1)
{
entryDirPath=entryFilePath.substring(0,index);
}
else
{
entryDirPath="";
}
entryDir=newFile(entryDirPath);
//如果文件夹路径不存在,则创建文件夹
if(!entryDir.exists()||!entryDir.isDirectory())
{
entryDir.mkdirs();
}
//创建解压文件
entryFile=newFile(entryFilePath);
if(entryFile.exists())
{
//检测文件是否允许删除,如果不允许删除,将会抛出SecurityException
=newSecurityManager();
securityManager.checkDelete(entryFilePath);
//删除已存在的目标文件
entryFile.delete();
}
//写入文件
bos=newBufferedOutputStream(newFileOutputStream(entryFile));
bis=newBufferedInputStream(zip.getInputStream(entry));
while((count=bis.read(buffer,0,bufferSize))!=-1)
{
bos.write(buffer,0,count);
}
bos.flush();
bos.close();
}
}
publicstaticvoidmain(String[]args)
{
StringzipPath="d:\ziptest\zipPath";
Stringdir="d:\ziptest\rawfiles";
StringzipFileName="test.zip";
try
{
zip(dir,zipPath,zipFileName);
}
catch(Exceptione)
{
e.printStackTrace();
}
StringzipFilePath="D:\ziptest\zipPath\test.zip";
StringunzipFilePath="D:\ziptest\zipPath";
try
{
unzip(zipFilePath,unzipFilePath,true);
}
catch(Exceptione)
{
e.printStackTrace();
}
}
}
⑤ zip的文件,怎么解压缩打开
zip格式用手机怎么打开是很多朋友关注的话题,其实zip格式的文件是一种经过压缩的文件,通过压缩之后,文件的体积会变小,从而更有利于在网络上传播。经过压缩的文件,如果想要再次使用,就必须通过解压缩后才能使用,下面不妨就跟着小编一起去看看zip格式用手机如何打开吧。
以上就是ip格式用手机如何打开的具体介绍和操作方法了,希望可以帮助到你哦。
⑥ java怎么读取Zip和RAR里面的文件啊
ZipInputStream是一个指向ZIP文件的流,这个流最重要的方法就是getNextEntry方法,一个zip文件可以包含好几个被压缩的文件,这个方法的功能就是返回下一个目录项,也就是返回zip文件中的下一项,并且把流指向这个目录文件项。getNextEntry的返回值是ZipEntry,它表示zip文件中的一个项,它可以返回这个文件项的大小、名称等。你可以根据它返回的文件大小调用ZipInputStream的read方法来读取需要的字节。给你一个例子:public class ZipTest {
public static void main(String args[]) throws FileNotFoundException, IOException{
ZipInputStream zis = new ZipInputStream(new FileInputStream ("c://a.zip"));//生成读取ZIP文件的流
ZipEntry ze = zis.getNextEntry();//取得下一个文件项
long size = ze.getSize();//取得这一项的大小
FileOutputStream fos = new FileOutputStream("c://"+ze.getName());//产生输出文件对象
for(int i= 0;i<size;i++){//循环读取文件并写入输出文件对象
byte c = (byte)zis.read();
fos.write(c);
}
fos.close();
zis.close();
}
}
⑦ 如何在java中实现对zip和rar文件的解压
java中有zip包,可以使用
publicvoidgetZipFiles(StringzipFile,StringdestFolder)throwsIOException{
BufferedOutputStreamdest=null;
ZipInputStreamzis=newZipInputStream(
newBufferedInputStream(
newFileInputStream(zipFile)));
ZipEntryentry;
while((entry=zis.getNextEntry())!=null){
System.out.println("Extracting:"+entry.getName());
intcount;
bytedata[]=newbyte[BUFFER];
if(entry.isDirectory()){
newFile(destFolder+"/"+entry.getName()).mkdirs();
continue;
}else{
intdi=entry.getName().lastIndexOf('/');
if(di!=-1){
newFile(destFolder+"/"+entry.getName()
.substring(0,di)).mkdirs();
}
}
FileOutputStreamfos=newFileOutputStream(destFolder+"/"
+entry.getName());
dest=newBufferedOutputStream(fos);
while((count=zis.read(data))!=-1)
dest.write(data,0,count);
dest.flush();
dest.close();
}
}
rar的只能用第三方api,比如junrar
https://github.com/edmund-wagner/junrar
⑧ java中怎么用cmd命令解压zip文件
对于zip文件,java有自带类库java.util.zip;可是要想解压rar文件只能靠第三方类库,我试过两个:com.github.junrar和de.innosystec.unrar,前者解压时可能会出现crcError,后者pom配置时报错;利用cmd命令调用winRAR进行解压,无疑方便快捷很多。
调用cmd命令
public static boolean exe(String cmd) {
Runtime runtime = Runtime.getRuntime(); try {
Process p = runtime.exec(cmd);
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream(),"GBK"));
String line = reader.readLine(); while(line!=null) {
logger.info(line);
line = reader.readLine();
}
reader.close(); if(p.waitFor()!=0) { return false;
}
} catch (IOException e) { // TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) { // TODO Auto-generated catch block
e.printStackTrace();
} return true;
}
首先利用runtime.exec()执行指令,得到process,从process.getInputStream()中获取回显字符并打印,打印回显时可能会出现中文乱码,这个和操作系统编码有关,我这里是GBK编码,所以在new inputstreamReader时加入了编码参数”GBK“
命令行字符串
如果需要调用cmd命令,如cd等,可写”cmd c cd 目录”。对于直接调用exe执行,则可以写成”exe文件绝对路径 参数”,在命令行字符串中,含有空格的路径或者字符串应该再加上引号,即””exe文件绝对路径” ”参数”“
winRAR调用
我这里安装目录是C:/Program Files/WinRAR,将D:1.rar 解压到D:,则写成””C:/Program Files/WinRAR/unRar.exe” x -y D:/1.rar D:/”,x代表绝对路径解压,-y表示全部确定;压缩的命令如下:“”C:/Program Files/WinRAR/rar.exe” a -ep1 D:2.rar D:源目录”,a表示添加文件到压缩文件,-ep1表示排除基本目录,如D:winrar ar这个目录,如果没有-ep1那么压缩包中会出现winrar目录路径,而加了之后就只将当前目录打包,只有rar目录
⑨ java如何解压一个ZIP压缩过的数据
1楼的方法。先解压开后,你再把文件读成流,把数据存数据库
⑩ java如何直接解压zip格式二进制流
Java代码
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
class ZipTest {
// 压缩
public static void zip(String zipFileName, String inputFile)
throws Exception {
File f = new File(inputFile);
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
zipFileName));
zip(out, f, f.getName());
System.out.println("zip done");
out.close();