




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
package com.zhiyin.io;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.OutputStream;import java.io.OutputStreamWriter;import java.util.zip.ZipEntry;import java.util.zip.ZipInputStream;import java.util.zip.ZipOutputStream;/* * author Administrator *IO工具类 */public class IOUtil public static void FileToFile(String filepath1,String filepath2)FileInputStream fis = null;FileOutputStream fos = null;try fis = new FileInputStream(filepath1);fos = new FileOutputStream(filepath2);byte buf = new byte1024*2; /2Kint len = 0;while(len = fis.read(buf)!=-1)fos.write(buf, 0, len);System.out.println(拷贝结束!); catch (Exception e) e.printStackTrace();finallyif(fos!=null)try fos.close(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();if(fis!=null)try fis.close(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();public static void FileToConsole(String path)BufferedInputStream bis = null;BufferedOutputStream bos = null;try bis = new BufferedInputStream(new FileInputStream(path);bos = new BufferedOutputStream(System.out);byte buf = new byte1024*2;int len = 0;while(len=bis.read(buf)!=-1)bos.write(buf, 0, len);bos.flush(); catch (Exception e) / TODO Auto-generated catch blocke.printStackTrace();finallyif(bos!=null)try bos.close(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();if(bis!=null)try bis.close(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();public static void ConsoleToFile(String path)BufferedReader br = null;BufferedWriter bw = null;try br = new BufferedReader(new InputStreamReader(System.in);bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path);String line = null;while(line = br.readLine()!=null)if(quit.equals(line)System.out.println(读写完成);break;bw.write(line);bw.newLine();bw.flush(); catch (Exception e) / TODO Auto-generated catch blocke.printStackTrace();finallyif(bw!=null)try bw.close(); catch (Exception e) / TODO Auto-generated catch blocke.printStackTrace();if(br!=null)try br.close(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();public static void ConsoleToConsole()BufferedReader br = new BufferedReader(new InputStreamReader(System.in);BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out);String line = null;try while(line = br.readLine()!=null)if(quit.equals(line)System.out.println(程序读取结束);break;bw.write(line);bw.newLine();bw.flush(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();finallyif(bw!=null)try bw.close(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();if(br!=null)try br.close(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();/* * param sourthpath 源文件或目录绝对路径 * param tarpath 目标目录绝对路径 * */public static void copy(String sourthpath,String tarpath)File source = new File(sourthpath);File tarFile = new File(tarpath,source.getName();if(source.isDirectory()tarFile.mkdir(); /如果是目录,则创建目录File files = source.listFiles();for(int i=0;ifiles.length;i+)copy(filesi.getAbsolutePath(),tarFile.getAbsolutePath();else InputStream is = null;OutputStream os = null;try is = new FileInputStream(source);os = new FileOutputStream(tarFile);byte buf = new byte1024*2;int len = 0;while(len = is.read(buf)!=-1)os.write(buf, 0, len);System.out.println(拷贝结束); catch (Exception e) / TODO Auto-generated catch blocke.printStackTrace();finallyif(os!=null)try os.close(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();if(is!=null)try is.close(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();/* * param sourcepath 源目录或源文件绝对路径 * param tarpath 目标.zip压缩文件绝对路径 */public static void zip(String sourcepath,String tarpath)File file = new File(sourcepath);try ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(tarpath);String basedir = ;zip(file,zos,basedir);zos.close(); catch (Exception e) e.printStackTrace();public static void zip(File file,ZipOutputStream zos,String basedir)if(file.isDirectory()System.out.println(压缩目录:+file.getAbsolutePath();zipDirectory(file,zos,basedir);else System.out.println(压缩文件:+file.getAbsolutePath();zipFile(file, zos, basedir);public static void zipDirectory(File file,ZipOutputStream zos,String basedir)File files = file.listFiles();for(int i=0;ifiles.length;i+)zip(filesi,zos,basedir+file.getName()+/);public static void zipFile(File file,ZipOutputStream zos,String basedir)try ZipEntry entry = new ZipEntry(basedir+file.getName();zos.putNextEntry(entry);BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file);int len = 0;byte buf = new byte1024*2;while(len = bis.read(buf)!=-1)zos.write(buf,0, len);bis.close(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();/* * param source 待解压缩.zip文件 * param tar 解压后存放目录 */public static void unzip(String source,String tar)try File target = new File(tar);target.mkdir();ZipInputStream zis = new ZipInputStream(new FileInputStream(source);ZipEntry entry = null;while (entry = zis.getNextEntry() != null) File tarFile = new File(target, entry.getName();if(entry.isDirectory()tarFile.mkdir();elseOutputStream os = new FileOutputStream(tarFile);byte b
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 甲乙合作开公司合同范本
- 空调保养维修协议合同书
- 烟酒货架转让协议书模板
- 村委临时用工劳务协议书
- 瑜伽老师安全协议书范本
- 电力照明工程承包协议书
- 自制造跑车出售合同范本
- 空调排风管清洗合同范本
- 离婚房屋公证合同协议书
- 渔网机租赁合同协议范本
- EN 4644-001-2017(高清正版)
- BICC协议介绍
- 盾构刀具大解析
- 公铁联运物流园区及配套项目建议书写作模板
- 预应力混凝土简支T形梁桥毕业论文
- 变频器变频altivar71说明书
- 农村饮用水工程监理规划
- WBS BOM操作手册
- 维瓦尔迪《The Four Seasons四季》【春】小提琴 钢琴伴奏谱
- 铁路文物保护管理暂行办法
- 有限空间作业安全告知牌及警示标志(共21页)
评论
0/150
提交评论