温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

JAVA输入输出流详解(G)

发布时间:2020-08-08 19:52:33 来源:ITPUB博客 阅读:156 作者:lotuszm 栏目:编程语言

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

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"则返回通过字节获得的文件内容
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI