java8_api_misc
属性文件处理
概念
加载并读取文件内容
修改文件内容
获取系统属性
该文件是一个文本文件,以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的更多相关文章
随机推荐
- Python字典的使用与处理
在Python中,字典{dict}是比较常用的一个数据类型,使用键-值(key-value)存储 与列表[list]相比,字典具有极快的查找和插入速度,不会随着key-value的增加而变慢,但是相应 ...
- Mysql 存储过程查询结果赋值到变量的方法
drop table if exists test_tbl; create table test_tbl (name varchar(20), status int(2)); insert into ...
- Jsの练习-数组常用方法 -forEach()
forEach() : 对数组进行遍历循环,对数组中的每一项运行给定函数. 格式: arr.forEach(function(value,index){}) <!DOCTYPE html> ...
- Spine用于Timeline(NullReferenceException: Object reference not set to an instance of an object pine.Unity.Editor.AnimationReferenceAssetEditor.OnInspectorGUI ())
报错信息:Spine.Unity.Editor.AnimationReferenceAssetEditor.OnInspectorGUI () (at Assets/Extention/Spine/E ...
- Unity3D Button组管理(给按钮的onclick事件“传递参数”)
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI; // ...
- ACE如何生成VS工程之mwc.pl用法
1.先写个mwc文件,文件名为hello.mwc workspace { hello.mpc} 2.写mpc文件,文件名为hello.mpc project(hello):aceexe, acexml ...
- 《贝贝GO》服务条款
服务条款 一.服务条款的确认与接收 1.贝贝GO客户端软件(以下简称“本软件”)各项电子服务的所有权和运作权归属于“东莞市山水信息技术有限公司”(以下称“本公司”)所有,本软件提供的服务将完全按照其发 ...
- java多态——基础
多态 定义: 一个接口,多种实现,就是多种状态 价值: 特点:多态存在的特点,就是必须要有继承.覆盖.父类变量调用子类对象 场景: 首先检查父类中是否有该方法,如果没有,则编译错误:如果有,则 ...
- esLint 配置
默认eslint规则: 代码末尾不能加分号 ;(强迫症的我受不了)代码中不能存在多行空行:(这个我更也忍不了)tab键不能使用,必须换成两个空格:(超级不习惯)代码中不能存在声明了但未使用的变量:(这 ...
- python sheet写入数据
import pandas as pd from pandas import DataFrame import openpyxl from openpyxl import load_workbook ...