属性文件处理
    概念
    加载并读取文件内容
    修改文件内容
    获取系统属性
    
    该文件是一个文本文件,以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. 测试使用 Open Live Writer写博客

    这里测试文字的显示: 第一段 第二段 第三段 这里测试图片的显示: 这里测试视频的显示: 测试不了,是不是版权问题?

  2. socket.io 实现简易聊天

    客户端: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  3. unity UI如何开启(显示)或者关闭(隐藏)Panel界面最好?

    https://segmentfault.com/a/1190000012357091 unity UI如何开启(显示)或者关闭(隐藏)Panel界面,相信大家都是知道的,但是如何做最好呢? 可能大家 ...

  4. selenium中iframe的切换

    #第一层是默认层, 第二层是新建标签的层,第三层是百度的那层from selenium import webdriverimport timedriver=webdriver.Chrome()driv ...

  5. ACE + TAO工程中的Messenger启动过程

    1.启动NameService服务 F:\ACESource\ACE_wrappers\TAO\orbsvcs\Naming_Service>tao_cosnaming.exe -o F:\AC ...

  6. Mac下安装证书fiddlerRoot.cer

    Step 1: 设置Mac的代理如下 Step 2:打开127.0.0.1:8888,下载fiddlerRoot.cer; Step 3:下载好了,双击安装,但是默认这个证书是不可信的,你需要在钥匙串 ...

  7. 石头的Xcode学习列表

    http://www.cnblogs.com/JangoJing/tag/xcode/

  8. Linux命令rz

    rz :上传文件:sz: 下载文件: 在linux 系统中,使用rz(或 sz) 命令是,提示 -bash: rz(或者是sz): command not found .这个时候,说明没有安装 lrz ...

  9. ejabberd之开题篇

    ejabberd是基于Jabber/XMPP协议的即时通讯服务器.采用Erlang/OTP开发.它的特点是,跨平台,容错,集群和模块化.     因为自己本身是基于erlang工作,而且听到有不少的公 ...

  10. 小程序 movable-area 实现悬浮窗效果

    最近做一个小程序 实现页面内悬浮窗的效果 给自己制定两个方案: 1.通过一个自定义的组件,通过触摸事件进行实现: 2.使用微信的movable移动组件实现: 第一种方案: 结果:实现了 悬浮窗和自动靠 ...