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

定制建站费用3500元

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

成都品牌网站建设

品牌网站建设费用6000元

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

成都商城网站建设

商城网站建设费用8000元

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

成都微信网站建设

手机微信网站建站3000元

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

建站知识

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

JAVA输入输出流详解(G)

import java.util.*;
import java.util.zip.*;
import java.io.*;

创新互联主营大荔网站建设的网络公司,主营网站建设方案,App定制开发,大荔h5微信平台小程序开发搭建,大荔网站营销推广欢迎大荔等地区企业咨询

class ZipFileHandle{
private String[] FileNameArray; //真实文件名存放数组
private String[] FileNameArrayShow; //需要显示的文件名存放数组
private ZipInputStream zipFile; //zip输入流对象
private ZipEntry entry; //zip文件入口对象
private int zipFileCount = 0; //zip中的文件总数[@more@]/**
*
初始化各个参数

*通过类的套嵌来访问文件
*将得到文件的清单附值给数组,以便在后面用户选择时从数组中获得文件名
*/
public ZipFileHandle(File file){
try{
while (!(file.exists())) {
System.out.println("Plase input right path again: ");
BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in));
String filepath = userInput.readLine();
file = new File(filepath);
}
zipFile = new ZipInputStream(new FileInputStream(file));
while ((zipFile.getNextEntry()) != null){
zipFileCount++;
}
FileNameArray = new String[zipFileCount];
FileNameArrayShow = new String[zipFileCount];
}catch(IOException e){
System.out.println("初始化错误!!!");
e.printStackTrace();
}
}
/**
*生成文件目录
*根据show的值来确定返回值
*如果show的值为"sh"则返回在屏幕上显示的名称
*如果show的值为"gr"则返回实际名称
*/
public String[] getFileNameList(String show,File file){
try{
int i = 0;
String FileName;
zipFile = new ZipInputStream(new FileInputStream(file));
while ((entry = zipFile.getNextEntry()) != null){
FileName = entry.getName();
//真实文件名附值
FileNameArray[i] = FileName;
//显示文件名附值
if (FileName.equals("")) FileName = "...";
FileName = Integer.toString(i) + "-|" + FileName;
FileNameArrayShow[i] = FileName;
i++;
}
zipFile.close();
//根据条件返回文件数组
if(show == "sh"){
return FileNameArrayShow;
}else{
return FileNameArray;
}
}catch(IOException e){
System.out.println("读取zip文件内的文件名出错!!!");
e.printStackTrace();
return null;
}
}

/**
*读取文件内容
*根据传递进来的zip文件对象和
*zip中所要显示的文件
*用户根据type来选择返回的是unicode信息还字节信息
*如果type是"Str"则返回字符串信息,"Byte"则返回通过字节获得的文件内容
网页标题:JAVA输入输出流详解(G)
文章位置:http://bjjierui.cn/article/pjcojg.html

其他资讯