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的更多相关文章
随机推荐
- 关于系统弹出错误:429 , ActiveX 部件不能创建对象 的解决方法
例如:win7 win10的系统,有时候运行某些软件会出现:429 , ActiveX 部件不能创建对象 的情况. 提示: "运行时错误'429': ActiveX 部件不能创建对象&quo ...
- 微信小程序swiper 前后边距的使用
小程序中有一个组件swiper 就是滑块视图容器 其中提供了两个属性 previous-margin:前边距,可用于露出前一项的一小部分 next-margin:后边距,可用于露出后一项的 ...
- 体验ToLua框架下热更新(Phpstudy)
一.关于热更新的详细流程 首先我们需要需要将本机电脑作为服务器打开,这是第一步 1.1.1如何确定我们的电脑是作为服务器打开的. 我们打开一个浏览器在地址栏中输入127.0.0.1.或者是localh ...
- 根据图片URL获取图片的尺寸【Swift语言实现】
import UIKit extension UIImage { /// 获取网络图片尺寸 /// /// - Parameter url: 网络图片链接 /// - Returns: 图片尺寸siz ...
- 2017年4月28日16:40:40 log
//TODO order CreateOrderServiceHandler generateManagementCustomer 子活动名称和uid
- WCF分布式4:客户端访问寄宿在IIS中的WCF服务
部署过程比较简单,新建一个站点,指向服务的物理路径,设置一个端口.即可. 新建的站点对应一个应用程序池,设置应用程序池中的.NET版本为4.0 写一个测试客户端,访问IIS中的WCF服务,可能会出现, ...
- Wpf binging (二) 集合绑定
除去简单控件的数据绑定,还有集合控件的数据绑定,一下示例 这发现 source 变成了 itemsSource Path 变成了 DisplayMemberPath itemsSource:代 ...
- canvas 添加线和删除线 及获取相关位置信息源码
其他相关链接: https://github.com/lusase/lineDrawer.git https://www.jb51.net/css/359062.html https://www.jb ...
- Linux环境下安装nginx
#一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩cd /usr/local/devmkdir nginxcd nginxmkdir softcd soft # ...
- C#入门基本概念
一.版本号的命名规则 大部分时候是在名字后面加些数字表示不同的版本.其中以加上年份号最为简单明了.比如 Visual Studio 2008.但是大部分人还是不用这个方式.因为年份号中没有带来跟多的信 ...