网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

java压缩视频代码,java上传视频调用压缩软件

android中如何代码压缩音频视频文件呢

知道怎么压缩文件,音视频文件应该差不多吧O.O

创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都做网站、网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的南县网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

package com.once;

import java.io.*;

import java.util.ArrayList;

import java.util.Collection;

import java.util.Enumeration;

import java.util.zip.ZipEntry;

import java.util.zip.ZipException;

import java.util.zip.ZipFile;

import java.util.zip.ZipOutputStream;

/**

* Java utils 实现的Zip工具

*

* @author once

*/

public class ZipUtils {

private static final int BUFF_SIZE = 1024 * 1024; // 1M Byte

/**

* 批量压缩文件(夹)

*

* @param resFileList 要压缩的文件(夹)列表

* @param zipFile 生成的压缩文件

* @throws IOException 当压缩过程出错时抛出

*/

public static void zipFiles(CollectionFile resFileList, File zipFile) throws IOException {

ZipOutputStream zipout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(

zipFile), BUFF_SIZE));

for (File resFile : resFileList) {

zipFile(resFile, zipout, "");

}

zipout.close();

}

/**

* 批量压缩文件(夹)

*

* @param resFileList 要压缩的文件(夹)列表

* @param zipFile 生成的压缩文件

* @param comment 压缩文件的注释

* @throws IOException 当压缩过程出错时抛出

*/

public static void zipFiles(CollectionFile resFileList, File zipFile, String comment)

throws IOException {

ZipOutputStream zipout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(

zipFile), BUFF_SIZE));

for (File resFile : resFileList) {

zipFile(resFile, zipout, "");

}

zipout.setComment(comment);

zipout.close();

}

/**

* 解压缩一个文件

*

* @param zipFile 压缩文件

* @param folderPath 解压缩的目标目录

* @throws IOException 当解压缩过程出错时抛出

*/

public static void upZipFile(File zipFile, String folderPath) throws ZipException, IOException {

File desDir = new File(folderPath);

if (!desDir.exists()) {

desDir.mkdirs();

}

ZipFile zf = new ZipFile(zipFile);

for (Enumeration? entries = zf.entries(); entries.hasMoreElements();) {

ZipEntry entry = ((ZipEntry)entries.nextElement());

InputStream in = zf.getInputStream(entry);

String str = folderPath + File.separator + entry.getName();

str = new String(str.getBytes("8859_1"), "GB2312");

File desFile = new File(str);

if (!desFile.exists()) {

File fileParentDir = desFile.getParentFile();

if (!fileParentDir.exists()) {

fileParentDir.mkdirs();

}

desFile.createNewFile();

}

OutputStream out = new FileOutputStream(desFile);

byte buffer[] = new byte[BUFF_SIZE];

int realLength;

while ((realLength = in.read(buffer)) 0) {

out.write(buffer, 0, realLength);

}

in.close();

out.close();

}

}

/**

* 解压文件名包含传入文字的文件

*

* @param zipFile 压缩文件

* @param folderPath 目标文件夹

* @param nameContains 传入的文件匹配名

* @throws ZipException 压缩格式有误时抛出

* @throws IOException IO错误时抛出

*/

public static ArrayListFile upZipSelectedFile(File zipFile, String folderPath,

String nameContains) throws ZipException, IOException {

ArrayListFile fileList = new ArrayListFile();

File desDir = new File(folderPath);

if (!desDir.exists()) {

desDir.mkdir();

}

ZipFile zf = new ZipFile(zipFile);

for (Enumeration? entries = zf.entries(); entries.hasMoreElements();) {

ZipEntry entry = ((ZipEntry)entries.nextElement());

if (entry.getName().contains(nameContains)) {

InputStream in = zf.getInputStream(entry);

String str = folderPath + File.separator + entry.getName();

str = new String(str.getBytes("8859_1"), "GB2312");

// str.getBytes("GB2312"),"8859_1" 输出

// str.getBytes("8859_1"),"GB2312" 输入

File desFile = new File(str);

if (!desFile.exists()) {

File fileParentDir = desFile.getParentFile();

if (!fileParentDir.exists()) {

fileParentDir.mkdirs();

}

desFile.createNewFile();

}

OutputStream out = new FileOutputStream(desFile);

byte buffer[] = new byte[BUFF_SIZE];

int realLength;

while ((realLength = in.read(buffer)) 0) {

out.write(buffer, 0, realLength);

}

in.close();

out.close();

fileList.add(desFile);

}

}

return fileList;

}

/**

* 获得压缩文件内文件列表

*

* @param zipFile 压缩文件

* @return 压缩文件内文件名称

* @throws ZipException 压缩文件格式有误时抛出

* @throws IOException 当解压缩过程出错时抛出

*/

public static ArrayListString getEntriesNames(File zipFile) throws ZipException, IOException {

ArrayListString entryNames = new ArrayListString();

Enumeration? entries = getEntriesEnumeration(zipFile);

while (entries.hasMoreElements()) {

ZipEntry entry = ((ZipEntry)entries.nextElement());

entryNames.add(new String(getEntryName(entry).getBytes("GB2312"), "8859_1"));

}

return entryNames;

}

/**

* 获得压缩文件内压缩文件对象以取得其属性

*

* @param zipFile 压缩文件

* @return 返回一个压缩文件列表

* @throws ZipException 压缩文件格式有误时抛出

* @throws IOException IO操作有误时抛出

*/

public static Enumeration? getEntriesEnumeration(File zipFile) throws ZipException,

IOException {

ZipFile zf = new ZipFile(zipFile);

return zf.entries();

}

/**

* 取得压缩文件对象的注释

*

* @param entry 压缩文件对象

* @return 压缩文件对象的注释

* @throws UnsupportedEncodingException

*/

public static String getEntryComment(ZipEntry entry) throws UnsupportedEncodingException {

return new String(entry.getComment().getBytes("GB2312"), "8859_1");

}

/**

* 取得压缩文件对象的名称

*

* @param entry 压缩文件对象

* @return 压缩文件对象的名称

* @throws UnsupportedEncodingException

*/

public static String getEntryName(ZipEntry entry) throws UnsupportedEncodingException {

return new String(entry.getName().getBytes("GB2312"), "8859_1");

}

/**

* 压缩文件

*

* @param resFile 需要压缩的文件(夹)

* @param zipout 压缩的目的文件

* @param rootpath 压缩的文件路径

* @throws FileNotFoundException 找不到文件时抛出

* @throws IOException 当压缩过程出错时抛出

*/

private static void zipFile(File resFile, ZipOutputStream zipout, String rootpath)

throws FileNotFoundException, IOException {

rootpath = rootpath + (rootpath.trim().length() == 0 ? "" : File.separator)

+ resFile.getName();

rootpath = new String(rootpath.getBytes("8859_1"), "GB2312");

if (resFile.isDirectory()) {

File[] fileList = resFile.listFiles();

for (File file : fileList) {

zipFile(file, zipout, rootpath);

}

} else {

byte buffer[] = new byte[BUFF_SIZE];

BufferedInputStream in = new BufferedInputStream(new FileInputStream(resFile),

BUFF_SIZE);

zipout.putNextEntry(new ZipEntry(rootpath));

int realLength;

while ((realLength = in.read(buffer)) != -1) {

zipout.write(buffer, 0, realLength);

}

in.close();

zipout.flush();

zipout.closeEntry();

}

}

}

java实现压缩视频文件,但是压缩后并解压,提示文件损坏,我该怎么修改代码?

(1)网络传输状况不好(如断线过多,开的线程过多,服务器人太多导致不能连接太多等)导致下载下来的文件损坏!

(2)站点提供的的RAR压缩包本来就是损坏的(这个本站可以保证,所上传的视频及软件等都经过好几遍测试,绝对没问题)。

(3)所使用的下载工具不够完善,比如有的下载工具多开了几个线程后,下载的收尾工作很慢,有些时候下载到99%时数据就不再传输了,一定要人工操作才能结束(先停止下载接着再开始)。笔者就碰到过好几次这样的情况。结果是文件下载下来以后解压缩到快结束时CRC出错。

解决方法:本站为防止这样的事情发生,在每个压缩包里又加了一个备份,防止因以上原因导致的下载后不能用,还得重新下载的问题,只要你下载下来的那个压缩包里的备份是好的那就能把压缩包里的文件恢复能用。

步骤一:双击打开需要解压修复的压缩包,选择:工具——修复压缩文件。

步骤二:出现下边图片的修复框,等待修复完成,关闭窗口及解压缩窗口就可以了。

步骤三:这时你会发现你需要解压的压缩包旁边多了一个压缩包,名称为:fixed.***(你下载的视频名称).rar ,这个压缩包就是修复后的解压缩包,如果修复成功,解压这个名称为:fixed.***(你下载的视频名称).rar 的压缩包就可以了。

如果修复不成功,你再修复几次看看,如果不行,只有再重新下载了

求一个JAVA的压缩程序源代码。

package com.io2.homework;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.util.zip.ZipEntry;

import java.util.zip.ZipOutputStream;

/*压缩文件夹*/

public class MyMultipleFileZip

{

private String currentZipFilePath = "F:/MyZip.zip";

private String sourceFilePath;

private ZipOutputStream zos;

private FileInputStream fis;

public MyMultipleFileZip(String sourceFilePath)

{

try

{

this.sourceFilePath = sourceFilePath;

zos = new ZipOutputStream(new FileOutputStream(currentZipFilePath));

//设定文件压缩级别

zos.setLevel(9);

} catch (FileNotFoundException e)

{

e.printStackTrace();

}

}

// 在当前条目中写入具体内容

public void writeToEntryZip(String filePath)

{

try

{

fis = new FileInputStream(filePath);

} catch (FileNotFoundException e1)

{

e1.printStackTrace();

}

byte[] buff = new byte[1024];

int len = 0;

try

{

while ((len = fis.read(buff)) != -1)

{

zos.write(buff, 0, len);

}

} catch (IOException e)

{

e.printStackTrace();

}finally

{

if (fis != null)

try

{

fis.close();

} catch (IOException e)

{

e.printStackTrace();

}

}

}

// 添加文件条目

public void addFileEntryZip(String fileName)

{

try

{

zos.putNextEntry(new ZipEntry(fileName));

} catch (IOException e)

{

e.printStackTrace();

}

}

public void addDirectoryEntryZip(String directoryName)

{

try

{

zos.putNextEntry(new ZipEntry(directoryName + "/"));

} catch (IOException e)

{

e.printStackTrace();

}

}

// 遍历文件夹

public void listMyDirectory(String filePath)

{

File f = new File(filePath);

File[] files = f.listFiles();

if(files!=null)

{

for (File currentFile : files)

{

// 设置条目名称(此步骤非常关键)

String entryName= currentFile.getAbsolutePath().split(":")[1].substring(1);

// 获取文件物理路径

String absolutePath = currentFile.getAbsolutePath();

if (currentFile.isDirectory())

{

addDirectoryEntryZip(entryName);

//进行递归调用

listMyDirectory(absolutePath);

}

else

{

addFileEntryZip(entryName);

writeToEntryZip(absolutePath);

}

}

}

}

// 主要流程

public void mainWorkFlow()

{

listMyDirectory(this.sourceFilePath);

if(zos!=null)

try

{

zos.close();

} catch (IOException e)

{

e.printStackTrace();

}

}

public static void main(String[] args)

{

new MyMultipleFileZip("F:/fountainDirectory").mainWorkFlow();

}

}


网站题目:java压缩视频代码,java上传视频调用压缩软件
本文来源:http://bjjierui.cn/article/phdpcj.html

其他资讯