属性文件处理
    概念
    加载并读取文件内容
    修改文件内容
    获取系统属性
    
    该文件是一个文本文件,以properties作为其后缀,内容格式为
    key1=value1
    用于保存简单的配置信息,保存国际化资源

config.properties
#second
#Tue Feb 13 09:49:22 CST 2018
url=bbbb
pw=qqqqq
driver=odbc
id=fgy ============================
package java_20180213_api_misc; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties; public class PropertiesDemo { public static void main(String[] args) throws Exception {
Properties p1=new Properties();
//这个文件放在项目的根目录下,或者写明路径,才能找到
p1.load(new FileInputStream("WebContent\\config.properties"));
p1.forEach((n,v)->System.out.println(n+"="+v));
// System.out.println(p1.getProperty("id"));
p1.setProperty("pw", "qqqqq");
p1.store(new FileOutputStream("WebContent\\config.properties"), "second"); // Properties sp=System.getProperties();
// sp.forEach((n,v)->System.out.println(n+"="+v));
} }

zip格式处理
    zip格式介绍
    创建zip文件
    解压zip文件
    读取zip文件内容
    
    相关的类
        ZipEntry    zip文件中的一个条目
        ZipInputStream    从zip文件中读取ZipEntry
        ZipOutputStream    向zip文件中写入ZipEntry
        ZipFile        读取ZipEntry的工具类
    完成的任务
        创建zip文件
        解压zip文件
        读取zip文件内容

package java_20180213_api_misc;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.Deflater;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream; public class ZipDemo { public static void main(String[] args) throws Exception {
// createZip();
// unzip();
// list();
list2();
} // private static void createZip() throws Exception{
// try(ZipOutputStream zps=new ZipOutputStream(new FileOutputStream("WebContent\\txt\\aa.zip"))){
// zps.setLevel(Deflater.BEST_COMPRESSION);
// ZipEntry ze1=new ZipEntry("f2.txt");
// zps.putNextEntry(ze1);
// BufferedInputStream bis=new BufferedInputStream(new FileInputStream("WebContent\\txt\\f2.txt"));
// byte[] buffer=new byte[1024];
// int len=-1;
// while ((len=bis.read(buffer, 0, buffer.length))!=-1) {
// zps.write(buffer, 0, len);
// }
// bis.close();
//
// ZipEntry ze2=new ZipEntry("f4.txt");
// zps.putNextEntry(ze2);
// BufferedInputStream bis1=new BufferedInputStream(new FileInputStream("WebContent\\txt\\f3.txt"));
// byte[] buffer1=new byte[1024];
// int len1=-1;
// while ((len1=bis1.read(buffer1, 0, buffer1.length))!=-1) {
// zps.write(buffer1, 0, len1);
// }
// bis1.close();
// }
// }
// private static void unzip() throws Exception{
// try(ZipInputStream zis=new ZipInputStream(new FileInputStream("WebContent\\txt\\aa.zip"))){
// ZipEntry entry=null;
// while ((entry=zis.getNextEntry())!=null) {
// String name=entry.getName();
// String dir="txt"+File.separator+name;
// File file=new File(dir);
// if (!file.getParentFile().exists()) {
// file.getParentFile().mkdirs();
// }
// file.createNewFile();
// BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(file));
// byte[] buffer=new byte[1024];
// int len=-1;
// while ((len=zis.read(buffer, 0, buffer.length))!=-1) {
// bos.write(buffer, 0, len);;
// }
// bos.close();
// }
// }
// } // private static void list() throws Exception{
// ZipFile zf=new ZipFile("WebContent\\txt\\aa.zip");
// Enumeration<? extends ZipEntry> e=zf.entries();
// while (e.hasMoreElements()) {
// ZipEntry ze=e.nextElement();
// System.out.println(ze.getName());
// }
// }
private static void list2() throws Exception{
ZipFile zf=new ZipFile("WebContent\\txt\\aa.zip");
zf.stream().forEach(entry->System.out.println(entry.getName()));
} }

java8_api_misc的更多相关文章

随机推荐

  1. wifi编辑 centos

    ifconfig -a sudo iw dev 设置名称 scan

  2. 使用 ado.net访问数据库

    一.ADO.NET :用于连接数据库的技术   1.ADO.NET分为两大组件    DataSet:数据集    .NET FRAMWORK :用于连接到数据库,发送命令,检索结果   2.ADO. ...

  3. SQL Server实现读写分离提高系统并发

    转自:http://www.canway.net/Lists/CanwayOriginalArticels/DispForm.aspx?ID=666 在一些大型的网站或者应用中,单台的SQL Serv ...

  4. vue+element-ui实现表格编辑(增加或删除行,删除单行或删除多行)

    <template> <div class="app-container"> <div class="filter-container&qu ...

  5. @RequestMapping、@ResponseBody和@RequestBody的使用

    使用SSM框架进行Web开发时,经常在Controller中遇到@RequestMapping.@ResponseBody和@RequestMapping注解. 1.@RequsetMapping注解 ...

  6. 已经在Git Server服务器上导入了SSH公钥,可用TortoiseGit同步代码时,还是提示输入密码?

    GitHub虽好,但毕竟在国内访问不是很稳定,速度也不快,而且推送到上面的源码等资料必须公开,除非你给他交了保护费:所以有条件的话,建议大家搭建自己的Git Server.本地和局域网服务器都好,不信 ...

  7. Java 程序员必须了解的 7 个性能指标

    来源:王韵菲  本文中,小编搜集了7个最有影响的衡量标注,让你可以不依赖日志文件来了解应用程序.现在,让我们看看这些性能指标,并了解如何查看并收集它们:     1.响应时间和吞吐量 根据应用程序的响 ...

  8. C# WebSocket

    WebSocket 协议用于完全双工的双向通信.这种通信,一般在浏览器和Web服务器之间进行,但仅交流那些支持使用WebSocket协议的客户端信息.WebSocket维持一个打开的连接. Tcp发送 ...

  9. SharePoint 2013 新特性 (三) 破改式 —— 设计管理器的使用 [1.设备通道]

    首先,哥们儿们会问,为啥要有设计管理器呢,不是原来就可以编辑页面了么,原来那个编辑不了模板页和布局页,也不能打包,而且也看不到具体HTML代码,不能编辑CSS,当然,你安装的SharePoint De ...

  10. Java线程的创建及启动

    1.继承Thread类,重写该类的run()方法. package samTest; import java.util.Scanner; /** * Created by Sam on 2018-01 ...